# Default virtual host overrides all other virtual hosts

**URL:** <https://www.ruby-forum.com/t/default-virtual-host-overrides-all-other-virtual-hosts/237216>\
**Category:** NGINX\
**Created:** [October 30, 2013, 8:56am UTC](https://www.ruby-forum.com/t/default-virtual-host-overrides-all-other-virtual-hosts/237216 "2013-10-30T08:56:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [October 30, 2013, 8:56am UTC](https://www.ruby-forum.com/t/default-virtual-host-overrides-all-other-virtual-hosts/237216/1 "2013-10-30T08:56:12Z")

</div>

hopefully someone can help, i’ve been trying to set up nginx with  
virtual  
hosts but the default host always overrides any of the others that i  
specify.

here is my config file found in /etc/nginx/sites-enabled

server {  
listen 80;  
server\_name [sub.example.com](http://sub.example.com);  
return 404;  
}

server {  
listen 80 default;  
server\_name \*.example.com;  
return 501;  
}

and the access.log shows

_._._._ - - [30/Oct/2013:04:09:11 +0400] “GET / HTTP/1.1” 501 582  
“[http://sub.example.com/](http://sub.example.com/)” “Mozilla/5.0 (Macintosh; Intel Mac OS X  
10\_9\_0)  
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101  
Safari/537.36”  
_._._._ - - [30/Oct/2013:04:09:14 +0400] “GET / HTTP/1.1” 501 582  
“[http://www.example.com/](http://www.example.com/)” “Mozilla/5.0 (Macintosh; Intel Mac OS X  
10\_9\_0)  
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101  
Safari/537.36”

thanks in advance for any help / ideas.

Posted at Nginx Forum:

> **[default virtual host overrides all other virtual hosts](https://forum.nginx.org/read.php?2,244255,244255#msg-244255)**
>
> hopefully someone can help, i've been trying to set up nginx with virtual hosts but the default host always overrides any of the others that i specify. here is my config file found in /etc/nginx/sites-enabled server { listen 80; server\_name sub.exa
