# Nginx error. Server name hash bucket size exceeded

**URL:** https://discourse.roots.io/t/nginx-error-server-name-hash-bucket-size-exceeded/7905
**Category:** trellis
**Created:** 2016-10-15T20:19:21Z
**Posts:** 6

## Post 1 by @aitor — 2016-10-15T20:19:21Z

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](http://subdomain1.subdomain2.domain.com)**

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

---

## Post 2 by @fullyint — 2016-10-15T21:53:19Z

`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](http://lindowsadmin.com/nginx-emerg-could-not-build-server_names_hash-you-should-increase-server_names_hash_bucket_size-64/) which says “This error is due to long domain name.” It suggests adding `server_names_hash_bucket_size 64;` to the [`http` block](https://github.com/roots/trellis/blob/df376a0aec8aa273c85ea8dd3c8ac807bf4b0f3a/roles/nginx/templates/nginx.conf.j2#L34), 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](https://www.google.com/search?q=nginx+%22conflicting+server+name%22+%22on+0.0.0.0:80,+ignored%22)

---

## Post 3 by @aitor — 2016-10-16T07:09:11Z

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

Update: After add `server_names_hash_bucket_size 64`to **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.

---

## Post 4 by @fullyint — 2016-10-16T23:05:43Z

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`](https://github.com/roots/trellis/blob/df376a0aec8aa273c85ea8dd3c8ac807bf4b0f3a/roles/nginx/templates/nginx.conf.j2#L34).

```
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](http://nginx.org/en/docs/http/server_names.html#optimization)

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](https://roots.io/trellis/docs/nginx-includes/).

---

## Post 5 by @aitor — 2016-10-17T08:42:20Z

Ok. Thank you for your time.

---

## Post 6 by @RiFi2k — 2016-10-17T17:41:42Z

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.
