server_name that starts with a number

Maxim Dounin mdounin at
Tue Sep 26 14:15:28 UTC 2017


On Tue, Sep 26, 2017 at 02:42:41PM +0200, rainer at wrote:

> I have a website that has a server_name that starts with a number (or 
> two numbers, actually).
> I also have a catchall default_server configured with the server_name 
> "_".
> Now, it seems when the server_name starts with a number, it's ignored 
> and requests are routed to the default server.

Just a quick test, with the only the following server{} blocks in 
the http{} section:

    server {
        listen 8080;
        server_name _;
        return 200 $server_name\n;

    server {
        listen 8080;
        return 200 $server_name\n;

Testing it with curl:

$ curl -H 'Host:'
$ curl -H 'Host:'

So clearly it selects correct server based on the name provided in 
the request, even when there are names starting with a number.

> Can someone explain this?
> How do I fix this?

Most likely explanations are, in no particular order:

- you've configured it wrong;
- you are testing it wrong.

To find out what exactly happened and how to fix this, please 
provide the following:

- full yet minimal configuration you are able to reproduce the 
  behaviour in question (providing "nginx -T" output might be a 
  good idea);

- steps you use to test things.

Note well that testing with browsers is generally a bad idea, as 
browsers tend to cache responses.

Maxim Dounin

More information about the nginx mailing list