Nginx default server not used

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 config: user nginx;worker_processes 5;error_log /var/log/nginx/error.log warn; - Pastebin.com

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:

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
nginx config: user nginx;worker_processes 5;error_log /var/log/nginx/error.log warn; - Pastebin.com

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.

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:

On 20 February 2012 00:17, rj [email protected] 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.

Edho A. Wrote:

is empty.

nginx Info Page
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:

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
nginx Info Page
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:

Hello

On Mon, Feb 20, 2012 at 4:17 AM, rj [email protected] wrote:

Have you tried to clear your browser’s cache?


O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

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:
http://nginx.org/en/docs/http/request_processing.html#mixed_name_ip_based_servers

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: