Nginx error. Server name hash bucket size exceeded

Hi, I got an error trying to add a new site in a subdomain (without multisite). Specifically, when I add this site to staging/wordpress_sites.yml:

wordpress_sites:
  stage.obrunete.observatorio-municipal-brunete.org:
    site_hosts:
      - stage.obrunete.observatorio-municipal-brunete.org
    repo: git@github.com:aitormendez/obrunete.git
    branch: master
    multisite:
      enabled: false
    ...
    ...

If I remove this site, the server is provisioned without errors. This is the error:

nginx: [warn] conflicting server name "stage.506.red" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "stage.contraindicaciones.net" on
0.0.0.0:80, ignored
nginx: [warn] conflicting server name "stage.di-no-a-la-noche-en-blanco.net"
on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "stage.e451.net" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "stage.esterpartegas.com" on
0.0.0.0:80, ignored
nginx: [warn] conflicting server name "stage.lolafonseca.com" on 0.0.0.0:80,
ignored
nginx: [warn] conflicting server name "stage.luzdemiel.es" on 0.0.0.0:80,
ignored
nginx: [warn] conflicting server name "stage.mariadiazmontero.com" on
0.0.0.0:80, ignored
nginx: [warn] conflicting server name "stage.obrunete.observatorio-municipal-
brunete.org" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "stage.telmo.club" on 0.0.0.0:80,
ignored
nginx: [emerg] could not build server_names_hash, you should increase
server_names_hash_bucket_size: 64
nginx: configuration file /etc/nginx/nginx.conf test failed
fatal: [188.226.213.77]: FAILED! => {"changed": false, "cmd": ["nginx", "-t"], "delta": "0:00:00.020439", "end": "2016-10-15 19:55:31.986660", "failed": true, "rc": 1, "start": "2016-10-15 19:55:31.966221", "stderr": "nginx: [warn] conflicting server name \"stage.506.red\" on 0.0.0.0:80, ignored\nnginx: [warn] conflicting server name \"stage.contraindicaciones.net\" on 0.0.0.0:80, ignored\nnginx: [warn] conflicting server name \"stage.di-no-a-la-noche-en-blanco.net\" on 0.0.0.0:80, ignored\nnginx: [warn] conflicting server name \"stage.e451.net\" on 0.0.0.0:80, ignored\nnginx: [warn] conflicting server name \"stage.esterpartegas.com\" on 0.0.0.0:80, ignored\nnginx: [warn] conflicting server name \"stage.lolafonseca.com\" on 0.0.0.0:80, ignored\nnginx: [warn] conflicting server name \"stage.luzdemiel.es\" on 0.0.0.0:80, ignored\nnginx: [warn] conflicting server name \"stage.mariadiazmontero.com\" on 0.0.0.0:80, ignored\nnginx: [warn] conflicting server name \"stage.obrunete.observatorio-municipal-brunete.org\" on 0.0.0.0:80, ignored\nnginx: [warn] conflicting server name \"stage.telmo.club\" on 0.0.0.0:80, ignored\nnginx: [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size: 64\nnginx: configuration file /etc/nginx/nginx.conf test failed", "stdout": "", "stdout_lines": [], "warnings": []}

Is the first time I try to setup a subdomain1.subdomain2 URL: subdomain1.subdomain2.domain.com

I guess, I’m doing it wrong.
What is the proper way to do it? Thank you!

stage.obrunete.observatorio-municipal-brunete.org is the longest of the server_names listed in the error. A search for could not build server_names_hash, you should increase server_names_hash_bucket_size: 64
leads to this post which says “This error is due to long domain name.” It suggests adding server_names_hash_bucket_size 64; to the http block, which would unfortunately require you to edit Trellis core files.

If you’re interested in testing on a fresh instance of the latest Trellis and discover that Trellis does not handle long domain names, perhaps you’d want to submit a bug report or a PR to specify server_names_hash_bucket_size or make it configurable from the group_vars files.

You may want to also look into why you are getting
conflicting server name “some.name” on 0.0.0.0:80, ignored

1 Like

Thank you very much for the explanation. I will try to add server_names_hash_bucket_size 64to nginx.conf.j2

Update: After add server_names_hash_bucket_size 64to nginx.conf.j2 the error persists.

http {
  # https://discourse.roots.io/t/nginx-error-server-name-hash-bucket-size-exceed/7905/1
  server_names_hash_bucket_size 64;

  # Hide nginx version information.
  server_tokens off;
  ...

I’ll try to test it in a new Trellis installation to isolate the problem and submit a problem report.

1 Like

I can reproduce the error with stage.obrunete.observatorio-municipal-brunete.org on a fresh install. I can resolve the error with the following at the top of the http block.

server_names_hash_bucket_size 128;

[If] server name is defined as “too.long.server.name.example.org” then nginx will fail to start and display the error message… In this case, the directive value should be increased to the next power of two
– nginx docs

So, bumping server_names_hash_bucket_size up from 64 to 128 seems to resolve it.

Don’t worry about submitting a bug report. What we’ve figured out here is sufficient. I’ve started working on a Trellis feature to make server_names_hash_bucket_size configurable without having to modify Trellis core files. Time permitting, it would be an overhaul to Trellis nginx includes.

4 Likes

Ok. Thank you for your time.

I thought about proposing this as an add-on to the nginx.conf file and make it have a variable you could configure. I had to add this into my own personal setup a long time ago because of this same error and hosting multiple sites with long domain names.

I don’t know how far you got but I was able to make this happen just adding it to the main nginx.conf and adding a variable with the other nginx variables in the role.