Question

Failed to start nginx on ubuntu 16.04 server

Posted June 17, 2020 1.3k views
Nginx
root@ip-172-31-11-69:/# systemctl status nginx.service 
● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2020-06-17 03:24:27 UTC; 18min ago

Jun 17 03:24:27 ip-172-31-11-69 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 17 03:24:27 ip-172-31-11-69 nginx[20727]: nginx: [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size: 64
Jun 17 03:24:27 ip-172-31-11-69 nginx[20727]: nginx: configuration file /etc/nginx/nginx.conf test failed
Jun 17 03:24:27 ip-172-31-11-69 systemd[1]: nginx.service: Control process exited, code=exited status=1
Jun 17 03:24:27 ip-172-31-11-69 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Jun 17 03:24:27 ip-172-31-11-69 systemd[1]: nginx.service: Unit entered failed state.
Jun 17 03:24:27 ip-172-31-11-69 systemd[1]: nginx.service: Failed with result 'exit-code'.
root@ip-172-31-11-69:/# 

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

In the /etc/nginx/nginx.conf file update the http block to include the following

http {
    ...
    server_names_hash_bucket_size 64;
    ...
}

Test your configuration with nginx -t

  • Thanks @jasonjpeters for your response.

    Test is failing after updating the http block.

    root@ip-172-31-11-69:/home/ubuntu# nano /etc/nginx/nginx.conf
    root@ip-172-31-11-69:/home/ubuntu# nginx -t
    nginx: [emerg] "server_names_hash_bucket_size" directive is duplicate in /etc/nginx/sites-enabled/ec2-13-233-150-249.ap-south-1.compute.amazonaws.com.conf:1
    nginx: configuration file /etc/nginx/nginx.conf test failed
    root@ip-172-31-11-69:/home/ubuntu# 
    
    
    • http {
      
              ##
              # Basic Settings
              ##
      
              sendfile on;
              tcp_nopush on;
              tcp_nodelay on;
              keepalive_timeout 65;
              types_hash_max_size 2048;
              # server_tokens off;
      
              server_names_hash_bucket_size 64;
              # server_name_in_redirect off;
      
              include /etc/nginx/mime.types;
              default_type application/octet-stream;
      
              ##
              # SSL Settings
              ##
      
              ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
              ssl_prefer_server_ciphers on;
      
              ##
              # Logging Settings
              ##
      
              access_log /var/log/nginx/access.log;
              error_log /var/log/nginx/error.log;
      
              ##
              # Gzip Settings
              ##
      
              gzip on;
              gzip_disable "msie6";
      
              # gzip_vary on;
              # gzip_proxied any;
              # gzip_comp_level 6;
              # gzip_buffers 16 8k;
              # gzip_http_version 1.1;
              # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
      
              ##
              # Virtual Host Configs
              ##
      
              include /etc/nginx/conf.d/*.conf;
              include /etc/nginx/sites-enabled/*;
      }
      

      ^This is the http block in my nginx.conf file

    • You will need to make sure that directive is only declared once in all of your configuration files excluding the nginx.conf

Submit an Answer