title: Adding domain to NGINX config, need to increase server_names_hash_bucket_size, but HTTP directive is failing
body: <p>I need to move an existing site to another server. I'm having problems. This is the original (working) nginx config:</p>
  
  <pre><code># Define a default server, to catch requests directly to the servers IP or other non-valid sources/domains/etc.
  server {
      listen                          80 default_server;
      return                          444;
  }
  
  
  # main.domain1 (everything defaults to this subdomain, it's a domain hack)
  server {
      listen                          80;
      listen                          443 ssl;
      server_name                     main.domain1.com;
      ssl_certificate                 /etc/nginx/ssl/main.domain1.com.bundle.crt;
      ssl_certificate_key             /etc/nginx/ssl/main.domain1.com.key;
      root                            /www/main.domain1.com;
      index                           index.php index.html index.htm;
  
      location /blog {
          try_files                   $uri /?p=blog&amp;$args;
      }
  
      location /contact {
          try_files                   $uri /?p=contact&amp;$args;
      }
  
      location /pics {
          autoindex                   on;
      }
  
      location ~ /\. {
          return                      444;
      }
  
      location ~ \.php$ {
          #try_files                  $uri =404;
          fastcgi_split_path_info     ^(.+\.php)(/.+)$;
          #fastcgi_pass               unix:/var/run/php5-fpm.sock;
          fastcgi_pass                127.0.0.1:9000;
          fastcgi_index               index.php;
          include                     fastcgi_params;
      }
  }
  # no sub-domain or one of the other TLD's should direct to main.domain1.com
  server {
      listen                          80;
      listen                          443 ssl;
      server_name                     domain1.com .domain1.net .domain1.org;
      return                          301 $scheme://main.domain1.com$request_uri;
  }
  
  
  # domain2.com (note: this is just a testing domain for main.domain1 without the subdomain)
  server {
      listen                          80;
      server_name                     domain2.com;
      root                            /www/domain2.com;
      index                           index.php index.html index.htm;
  
      location /blog {
          try_files                   $uri /?p=blog&amp;$args;
      }
  
      location /contact {
          try_files                   $uri /?p=contact&amp;$args;
      }
  
      location /pics {
          autoindex                   on;
      }
  
      location ~ /\. {
          return                      444;
      }
  
      location ~ \.php$ {
          #try_files                  $uri =404;
          fastcgi_split_path_info     ^(.+?\.php)(/.+)$;
          #fastcgi_pass               unix:/var/run/php5-fpm.sock;
          fastcgi_pass                127.0.0.1:9000;
          include                     fastcgi_params;
          auth_basic                  "Restricted";
          auth_basic_user_file        /www/domain2.com/.htpasswd;
      }
  }
  
  
  # domain3.com
  server {
      listen                          80;
      server_name                     domain3.com;
      root                            /www/domain3.com;
      index                           index.php index.html index.htm;
  
      location ~ /\. {
          return                      444;
      }
  
      location ~ \.php$ {
          #try_files                  $uri =404;
          fastcgi_split_path_info     ^(.+\.php)(/.+)$;
          #fastcgi_pass               unix:/var/run/php5-fpm.sock;
          fastcgi_pass                127.0.0.1:9000;
          fastcgi_index               index.php;
          include                     fastcgi_params;
      }
  }
  
  
  # catches https traffic to these other domains and sends them to non-https
  # user will see ssl warning from a.ntivir.us before being redirected however
  # this is not ideal, but about all we can do I think
  server {
      listen                          443 ssl;
      server_name                     domain2.com domain3.com;
      return                          301 http://$host;
  }
  </code></pre>
  
  <p>My first try was to simply copy the server block for domain3, and append it with domain4.com substituted. I get this error when trying to restart/reload nginx:</p>
  
  <p>nginx: [emerg] could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32</p>
  
  <p>So, I wrap all the server blocks in the http {} directive and define server_names_hash_bucket_size 64 at the http level and nginx still fails to load saying the http directive isn't allowed here. From the nginx documentation, it says it needs to be the parent of all server blocks, so I don't understand where I need to increase the size.</p>