3

I have the following two server-blocks in my config-file in sites-available:

server {
       listen 80;
       server_name www.mydomain.be;

       root /usr/share/nginx/html;
       index index.html index.htm;


       location / {
              try_files $uri $uri/ =404;
      }
}

server {
       listen 80;
       server_name sub.mydomain.be;

       root /usr/share/nginx/sub;
       index index.html index.htm;


       location / {
              try_files $uri $uri/ =404;
      }
}

I also created an A-record for both www.domain.be and sub.domain.be with the IP of my server as value.

Yet, when I try to reload my nginx configuration with service nginx reload it fails.

When I remove the second server-block, it reloads as expected.

I know this topic is popular, and that there are loads of such [nginx][subdomain] questions here, but none of them seems to discuss explicitly how the following three things hang together:

  1. virtual hosts or server blocks in nginx (est. server_name matching)
  2. the effect of A-records on how nginx processes requests
  3. the need to add hosts to /etc/hosts

Right now I have the impression that a lack of knowledge of this bigger picture, rather than specific knowledge of nginx configuration prevents me from making this work.

Update:

Tracked down the problem

Initially I got a fail without any explanation.

Using

sudo nginx -c /etc/nginx/nginx.conf -t

I got this message

nginx: [emerg] could not build the server_names_hash, you should increase       server_names_hash_bucket_size: 32

after uncommenting

server_names_hash_bucket_size 64;

the problem was resolved.

5
  • There seems to be a server_name missing in front of each of the names? May 26, 2014 at 20:40
  • Thanks. I've corrected this, but I still get the same [fail] when I reload nginx. May 26, 2014 at 20:46
  • Yes, but why does it fail to reload? May 26, 2014 at 21:02
  • I just got a [fail] without any more info, but now I've sorted out the problem. (question updated) May 26, 2014 at 21:31
  • If you have resolved it, you can add your own answer to your own question and accept it after 24 hours. May 26, 2014 at 22:30

1 Answer 1

1

Tracked down the problem (which isn't related to A-records or to the /etc/hosts file)

Initially I got a fail without any explanation.

Using

sudo nginx -c /etc/nginx/nginx.conf -t

I got this message

nginx: [emerg] could not build the server_names_hash, you should increase       server_names_hash_bucket_size: 32

after uncommenting

server_names_hash_bucket_size 64;

in nginx.conf the problem was resolved.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .