# Nginx default server not used

**URL:** <https://www.ruby-forum.com/t/nginx-default-server-not-used/217018>\
**Category:** NGINX\
**Created:** [February 19, 2012, 8:23pm UTC](https://www.ruby-forum.com/t/nginx-default-server-not-used/217018 "2012-02-19T20:23:52Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [February 19, 2012, 8:23pm UTC](https://www.ruby-forum.com/t/nginx-default-server-not-used/217018/1 "2012-02-19T20:23:52Z")

</div>

Hi,

I am currently evaluating nginx as an apache replacement and came across  
some (at least for me) odd behavior and hope someone can explain to me  
what is happening.

nginx is ignoring my default server and instead picks a directory of a  
deleted server as the default. If I point some random domain at the  
server address for which no server configuration exists, nginx servers  
the directory of the removed server config instead the on defined as the  
default server.

OS: Debian Squeeze  
nginx version: nginx/1.0.12 dotdeb repository

> **[nginx version: nginx/1.0.12 dotdeb repositoryTLS SNI support enabledconfigur...](https://pastebin.com/JGVA7NnZ)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

nginx config: [user nginx;worker\_processes 5;error\_log /var/log/nginx/error.log warn; - Pastebin.com](http://pastebin.com/UFEuCPEG)

The directory served by nginx as the default is not mentioned anywhere  
in /etc/nginx. I added it previously as an additional server but have  
deleted it. Somehow nginx still remembers the server and servers it as  
the default for unknown server names.

Posted at Nginx Forum:

> **[nginx default server not used](https://forum.nginx.org/read.php?2,222679,222679#msg-222679)**
>
> Hi, I am currently evaluating nginx as an apache replacement and came across some (at least for me) odd behavior and hope someone can explain to me what is happening. nginx is ignoring my default server and instead picks a directory of a deleted...

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 19, 2012, 10:03pm UTC](https://www.ruby-forum.com/t/nginx-default-server-not-used/217018/2 "2012-02-19T22:03:48Z")

</div>

Hello!

On Sun, Feb 19, 2012 at 02:23:32PM -0500, rj wrote:

> default server.
> 
> OS: Debian Squeeze  
> nginx version: nginx/1.0.12 dotdeb repository  
> [nginx version: nginx/1.0.12 dotdeb repositoryTLS SNI support enabledconfigur - Pastebin.com](http://pastebin.com/JGVA7NnZ)  
> nginx config: [user nginx;worker\_processes 5;error\_log /var/log/nginx/error.log warn; - Pastebin.com](http://pastebin.com/UFEuCPEG)
> 
> The directory served by nginx as the default is not mentioned anywhere  
> in /etc/nginx. I added it previously as an additional server but have  
> deleted it. Somehow nginx still remembers the server and servers it as  
> the default for unknown server names.

Most likely reason is that you’ve forgot to reload nginx config,  
or reload failed for some reason (take a look at nginx error  
log).

The config you’ve posted suggests there is indeed syntax error in  
it (missing “}” at the end), though it may be unrelated problem  
introduced during posting. Running “nginx -t” will help to  
identify syntax errors, looking into error log will cover other  
possible cases like port conflicts and so on.

Maxim D.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 19, 2012, 10:18pm UTC](https://www.ruby-forum.com/t/nginx-default-server-not-used/217018/3 "2012-02-19T22:18:05Z")

</div>

Hi Maxim,

thank’s for the quick reply. The config seems to be ok. The missing } is  
most likely a copy/paste error when combining the different config files  
for pastebin.

I tried nginx -t already and it succeeds, so I assume the config is at  
least syntactical correct.

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok  
nginx: configuration file /etc/nginx/nginx.conf test is successful

I also restarted and reloaded the config several times via  
/etc/init.d/nginx {restart, reload, stop and start} without any  
success.  
Already checked the error log, unfortunately it is empty.  
The server is running and working otherwise as expected. It serves  
static and dynamic (php/ruby) content and also correctly passes requests  
to a java tomcat server without any problems. I have no clue what could  
trigger this odd behavior.  
It seems all server configurations work correctly except for the default  
config.

Cheers,  
rj

Posted at Nginx Forum:

> **[Re: nginx default server not used](https://forum.nginx.org/read.php?2,222679,222689#msg-222689)**
>
> Hi, I am currently evaluating nginx as an apache replacement and came across some (at least for me) odd behavior and hope someone can explain to me what is happening. nginx is ignoring my default server and instead picks a directory of a deleted...

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 19, 2012, 11:13pm UTC](https://www.ruby-forum.com/t/nginx-default-server-not-used/217018/4 "2012-02-19T23:13:50Z")

</div>

On 20 February 2012 00:17, rj [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> nginx: configuration file /etc/nginx/nginx.conf test is successful  
> config.
> 
> Cheers,  
> rj

As Maxim said, if you previously had a location and then removed it  
but you are still seeing vestiges of this, then it means one of the  
following:

1. You are still running the previous instance of Nginx.
2. You are still loading a conf file with the previous items in it.

There is no other option.

Since you say you have reloaded (assuming you don’t have two instances  
of nginx going), then it has to be #2.

So you have to look again at your setup carefully. Somewhere in there,  
you are loading something different from what you have been editing.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 20, 2012, 7:33am UTC](https://www.ruby-forum.com/t/nginx-default-server-not-used/217018/5 "2012-02-20T07:33:29Z")

</div>

## Edho A. Wrote:

> is empty.
> 
> > 
> 
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)  
> Yeah that was the first thing I had in mind but it wasn’t the reason.  
> Somehow nginx didn’t stop nor reload the config and as it didn’t give me  
> any warning I assumed it did what I ask. My fault for not properly  
> checking if it actually stopped or not.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,222679,222700#msg-222700](http://forum.nginx.org/read.php?2,222679,222700#msg-222700)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 20, 2012, 7:42am UTC](https://www.ruby-forum.com/t/nginx-default-server-not-used/217018/6 "2012-02-20T07:42:08Z")

</div>

## Nginx U. Wrote:

> > I tried nginx -t already and it succeeds, so I  
> > /etc/init.d/nginx {restart, reload, stop and  
> > trigger this odd behavior.  
> > means one of the  
> > don’t have two instances  
> > [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)  
> > Thanks, this was indeed the problem. I assumed that /etc/init.d/nginx  
> > {reload, restart, stop, start} worked, as I didn’t get any error message  
> > saying otherwise. I also couldn’t find anything in nginx or the syslogs  
> > regarding nginx, so didn’t thought this might be the problem. After  
> > reading your suggestion I had a look at the running processes after  
> > “shutting down” nginx, and it was still running. So it seems this was  
> > the problem, although I don’t know why.

I couldn’t find anything in the logs why nginx was unable to start/stop  
or reload the config. The only difference after killing and restarting  
nginx, that I could find, was that passenger now is spawned as a  
separate process and not as a child process of nginx. So maybe that was  
the reason, but I’m just guessing.

Thanks for the hint in the right direction. I’m probably to used to  
apaches warnings when it cannot restart. Next time I’ll check this  
first.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,222679,222701#msg-222701](http://forum.nginx.org/read.php?2,222679,222701#msg-222701)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 20, 2012, 2:17am UTC](https://www.ruby-forum.com/t/nginx-default-server-not-used/217018/7 "2012-02-20T02:17:10Z")

</div>

Hello

On Mon, Feb 20, 2012 at 4:17 AM, rj [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

Have you tried to clear your browser’s cache?

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 13, 2012, 8:13am UTC](https://www.ruby-forum.com/t/nginx-default-server-not-used/217018/8 "2012-06-13T08:13:11Z")

</div>

On Sat, Jun 09, 2012 at 04:41:23AM -0400, valinor wrote:

> server\_name default.domain.dom;  
> as for another server.  
> Considering the fact that we have described a server with the particular  
> ip address, our default server for that ip (although it is listening on  
> all IPs) would be ignored, and all queries to that particular ip, even  
> with “Host: default.domain.dom”, would be directed to  
> “some.server.domain.dom” as it becomes a default (first-described)  
> server for this listening schema.  
> We have to explicitly describe “listen \<particular.ip\>:80” on the  
> default server to enable it for this schema.
> 
> WBW, valinor

Here, you have two different listening addresses, 0.0.0.0:80 and  
\<particular.ip\>:80. Each of them may have its own “default server”.  
See here for details:

> **[How nginx processes a request](http://nginx.org/en/docs/http/request_processing.html#mixed_name_ip_based_servers)**
>
> nginx first decides which server should process the request. Let’s start with a simple configuration where all three virtual servers listen on port \*:80:

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 9, 2012, 10:41am UTC](https://www.ruby-forum.com/t/nginx-default-server-not-used/217018/9 "2012-06-09T10:41:42Z")

</div>

Hello

I have found another possible cause for nginx to ignore default server  
I have encountered it just now, and it is not your case, but maybe it  
would be helpful for someone

At example:

server {  
listen 80 default\_server;  
server\_name default.domain.dom;  
…  
}

server {  
listen \<particular.ip\>:80;  
server\_name some.server.domain.dom;  
…  
}

In this case, listening schema for the default server is _not\_the\_same_  
as for another server.  
Considering the fact that we have described a server with the particular  
ip address, our default server for that ip (although it is listening on  
all IPs) would be ignored, and all queries to that particular ip, even  
with “Host: default.domain.dom”, would be directed to  
“some.server.domain.dom” as it becomes a default (first-described)  
server for this listening schema.  
We have to explicitly describe “listen \<particular.ip\>:80” on the  
default server to enable it for this schema.

WBW, valinor

Posted at Nginx Forum:

> **[Re: nginx default server not used](https://forum.nginx.org/read.php?2,222679,227377#msg-227377)**
>
> Hi, I am currently evaluating nginx as an apache replacement and came across some (at least for me) odd behavior and hope someone can explain to me what is happening. nginx is ignoring my default server and instead picks a directory of a deleted...
