default server with custom 404

Francis Daly francis at
Thu Apr 7 12:17:02 UTC 2016

On Thu, Apr 07, 2016 at 10:31:31AM +0100, Robin Becker wrote:
> On 06/04/2016 23:14, Francis Daly wrote:

Hi there,

> >>Is there a way to customize my error page for this case?
> >
> >What you have done should work. Depending on the rest of your config,
> >of course.

> I suspect my issue has more to do with me not understanding the way
> server names are matched. I look in vain for some equivalent to
> apache2ctl -S, but can't find it. links to for the first,
and for the second.

Very approximately,

  nginx -T | grep 'listen\|server'

will indicate your server{} blocks, their contained listen directives,
and their contained server_name directives.

(Except: "nginx -T" isn't in v1.8.1. So grep in your config file, and
in any files that you "include" in it.)

When you know the IP:port the connection arrives on, plus the hostname
that is requested, you can probably work out which server{} block nginx
will choose to handle the request.

> I have only one vhost with the default_server present and thought that
> listen 80 default_server;
> would fire for servers without an explicit match. Some simple
> testing reveals another is matching, but I don't know which one yet.

For every unique "listen IP" or "listen IP:80" directive that you
have anywhere in your config, add the same line to this server{} with
default_server set.

(Which means: if you have somewhere "listen;", then you
add a line "listen default_server;" to your catch-all
server block.)

> As this is a live server I won't try the debug route there, just bad
> luck we got an IP address that had previous connections to some kind
> of music distribution.

Install nginx on your test machine. Configure it there until you are
happy that it does what you want. Then transfer the config to your
production machine.

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list