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.
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.
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.
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.
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.
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.
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.
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:
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.