Welcome to Centmin Mod Community
Become a Member

Nginx Can't restart nginx

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by Jon Snow, Aug 11, 2017.

  1. Jon Snow

    Jon Snow Active Member

    156
    25
    28
    Jun 30, 2017
    Ratings:
    +30
    Local Time:
    10:29 PM
    Nginx 1.13.4
    MariaDB 10.1.26
    • CentOS Version: CentOS 7 64bit
    • Centmin Mod Version Installed: 123.09beta01
    • Nginx Version Installed: i.e. 1.13.4
    • PHP Version Installed: 7.1.x (latest)
    • MariaDB MySQL Version Installed: I think the latest
    • When was last time updated Centmin Mod code base ? : Today
    • Persistent Config: Yes
    Nginx isn't restarting :

    systemctl status nginx.service spits out :

    Code (Text):
    [23:56][root@hostname.domain.com ~]# systemctl status nginx.service
    ● nginx.service - SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
       Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
       Active: failed (Result: exit-code) since Thu 2017-08-10 23:56:13 UTC; 34s ago
         Docs: man:systemd-sysv-generator(8)
      Process: 17425 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=1/FAILURE)
    
    Aug 10 23:56:13 hostname.domain.com systemd[1]: Starting SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server...
    Aug 10 23:56:13 hostname.domain.com nginx[17425]: Starting nginx: nginx: [emerg] access_log "/home/nginx/domains/domain.com/log/access.log" already def...2.conf:55
    Aug 10 23:56:13 hostname.domain.com nginx[17425]: [FAILED]
    Aug 10 23:56:13 hostname.domain.com systemd[1]: nginx.service: control process exited, code=exited status=1
    Aug 10 23:56:13 hostname.domain.com systemd[1]: Failed to start SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server.
    Aug 10 23:56:13 hostname.domain.com systemd[1]: Unit nginx.service entered failed state.
    Aug 10 23:56:13 hostname.domain.com systemd[1]: nginx.service failed.
    


    First it was duplication location / (but there wasn't duplicate). There is no duplicate access log files in the config file too. I generated a custom self-signed ssl vhost config file using the centminmod generator and pasted + restarted nginx, but I get the above error now.
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    Test nginx configuration using command
    Code (Text):
    nginx -t
     
  3. Jon Snow

    Jon Snow Active Member

    156
    25
    28
    Jun 30, 2017
    Ratings:
    +30
    Local Time:
    10:29 PM
    Nginx 1.13.4
    MariaDB 10.1.26
    Will do that in a bit. I'm rolling back to nginx v1.13.3 to see if that changes anything.
     
  4. Jon Snow

    Jon Snow Active Member

    156
    25
    28
    Jun 30, 2017
    Ratings:
    +30
    Local Time:
    10:29 PM
    Nginx 1.13.4
    MariaDB 10.1.26
    Alright, this didn't do anything helpful.

    Code (Text):
    # nginx -t
    nginx: [emerg] access_log "/home/nginx/domains/domain.com/log/access.log" already defined with conflicting parameters in /usr/local/nginx/conf/conf.d/domain.com.ssl.conf:55
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
    
     
  5. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    post contents of /usr/local/nginx/conf/conf.d/domain.com.ssl.conf

    and output from command
    Code (Text):
    grep -r access_log /usr/local/nginx/conf/conf.d
    
     
  6. Jon Snow

    Jon Snow Active Member

    156
    25
    28
    Jun 30, 2017
    Ratings:
    +30
    Local Time:
    10:29 PM
    Nginx 1.13.4
    MariaDB 10.1.26
    Code (Text):
    # Centmin Mod Getting Started Guide
    # must read http://centminmod.com/getstarted.html
    # For SPDY SSL Setup
    # read http://centminmod.com/nginx_configure_https_ssl_spdy.html
    
    # redirect from www to non-www  forced SSL
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    # server {
    #       listen   80;
    #       server_name domain.com www.domain.com;
    #       return 302 https://$server_name$request_uri;
    # }
    
    server {
      listen 443 ssl http2;
      server_name domain.com www.domain.com;
    
      ssl_dhparam /usr/local/nginx/conf/ssl/domain.com/dhparam.pem;
      ssl_certificate      /usr/local/nginx/conf/ssl/domain.com/domain.com.crt;
      ssl_certificate_key  /usr/local/nginx/conf/ssl/domain.com/domain.com.key;
      include /usr/local/nginx/conf/ssl_include.conf;
    
      http2_max_field_size 16k;
      http2_max_header_size 32k;
      # mozilla recommended
      ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA256:EECDH+ECDSA+SHA384:EECDH+aRSA+SHA256:EECDH+aRSA+SHA384:EECDH+AES128:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!CAMELLIA;
      ssl_prefer_server_ciphers   on;
      #add_header Alternate-Protocol  443:npn-spdy/3;
    
      # before enabling HSTS line below read centminmod.com/nginx_domain_dns_setup.html#hsts
      #add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
      #add_header X-Frame-Options SAMEORIGIN;
      #add_header X-Xss-Protection "1; mode=block" always;
      #add_header X-Content-Type-Options "nosniff" always;
      #spdy_headers_comp 5;
      ssl_buffer_size 1369;
      ssl_session_tickets on;
     
      # enable ocsp stapling
      #resolver 8.8.8.8 8.8.4.4 valid=10m;
      #resolver_timeout 10s;
      #ssl_stapling on;
      #ssl_stapling_verify on;
      #ssl_trusted_certificate /usr/local/nginx/conf/ssl/domain.com/domain.com-trusted.crt;  
    
    # ngx_pagespeed & ngx_pagespeed handler
    #include /usr/local/nginx/conf/pagespeed.conf;
    #include /usr/local/nginx/conf/pagespeedhandler.conf;
    #include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/domain.com/log/access.log combined buffer=256k flush=5m;
      error_log /home/nginx/domains/domain.com/log/error.log;
    
      include /usr/local/nginx/conf/autoprotect/domain.com/autoprotect-domain.com.conf;
      root /home/nginx/domains/domain.com/public;
      # uncomment cloudflare.conf include if using cloudflare for
      # server and/or vhost site
      #include /usr/local/nginx/conf/cloudflare.conf;
      include /usr/local/nginx/conf/503include-main.conf;
    
      # prevent access to ./directories and files
      #location ~ (?:^|/)\. {
      # deny all;
      #}  
    
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    
    # block common exploits, sql injections etc
    #include /usr/local/nginx/conf/block.conf;
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # Shows file listing times as local time
      #autoindex_localtime on;
    
      # Wordpress Permalinks example
      #try_files $uri $uri/ /index.php?q=$uri&$args;
    
      }
    
      include /usr/local/nginx/conf/pre-staticfiles-local-domain.com.conf;
      include /usr/local/nginx/conf/pre-staticfiles-global.conf;
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/php.conf;
     
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
    
    


    Code (Text):
    [00:31][root@hostname.domain.com ~]# grep -r access_log /usr/local/nginx/conf/conf.d
    /usr/local/nginx/conf/conf.d/domain.com.ssl.conf:  access_log /home/nginx/domains/domain.com/log/access.log combined buffer=256k flush=5m;
    /usr/local/nginx/conf/conf.d/virtual.conf:        access_log              /var/log/nginx/localhost.access.log     combined buffer=8k flush=1m;
    /usr/local/nginx/conf/conf.d/virtual.conf:        access_log   off;
    /usr/local/nginx/conf/conf.d/domain.com.conf:  access_log /home/nginx/domains/domain.com/log/access.log combined buffer=256k flush=60m;
    /usr/local/nginx/conf/conf.d/demodomain.com.conf:            access_log /home/nginx/domains/demodomain.com/log/access.log ;
    
     
  7. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    • your domain.com.conf has access_log with buffer=256k flush=5m
    • your domain.com.ssl.conf has access_log with buffer=256k flush=60m
    try setting those both to flush=5m and see

    flush=5m is the updated 123.09beta01 defaults
     
  8. Jon Snow

    Jon Snow Active Member

    156
    25
    28
    Jun 30, 2017
    Ratings:
    +30
    Local Time:
    10:29 PM
    Nginx 1.13.4
    MariaDB 10.1.26
    It's weird because the non ssl confiig file was 60m :
    Code (Text):
    access_log /home/nginx/domains/ablackweb.com/log/access.log combined buffer=256k flush=60m;

    But I edited it and changed it to 5m so they match.

    Now I get :
    Code (Text):
    [00:43][root@hostname.domain.com ~]# systemctl status nginx.service
    ● nginx.service - SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
       Loaded: loaded (/etc/rc.d/init.d/nginx; bad; vendor preset: disabled)
       Active: failed (Result: exit-code) since Fri 2017-08-11 00:43:19 UTC; 10s ago
         Docs: man:systemd-sysv-generator(8)
      Process: 10541 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=1/FAILURE)
    
    Aug 11 00:43:19 hostname.domain.com systemd[1]: Starting SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server...
    Aug 11 00:43:19 hostname.domain.com nginx[10541]: Starting nginx: nginx: [emerg] duplicate location "/" in /usr/local/nginx/conf/conf.d/domain.com.ssl.conf:70
    Aug 11 00:43:19 hostname.domain.com nginx[10541]: [FAILED]
    Aug 11 00:43:19 hostname.domain.com systemd[1]: nginx.service: control process exited, code=exited status=1
    Aug 11 00:43:19 hostname.domain.com systemd[1]: Failed to start SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server.
    Aug 11 00:43:19 hostname.domain.com systemd[1]: Unit nginx.service entered failed state.
    Aug 11 00:43:19 hostname.domain.com systemd[1]: nginx.service failed.
    
     
  9. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    Code (Text):
    nginx -t
    

    ?
     
  10. Jon Snow

    Jon Snow Active Member

    156
    25
    28
    Jun 30, 2017
    Ratings:
    +30
    Local Time:
    10:29 PM
    Nginx 1.13.4
    MariaDB 10.1.26
    Code (Text):
    # nginx -t
    nginx: [emerg] duplicate location "/" in /usr/local/nginx/conf/conf.d/domain.com.ssl.conf:70
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
    
     
  11. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    what's 70th line of /usr/local/nginx/conf/conf.d/domain.com.ssl.conf ?

    cat with -n flag to list line numbers
    Code (Text):
    cat -n /usr/local/nginx/conf/conf.d/domain.com.ssl.conf
    
     
  12. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    also you can grep for all location / context matches too
    Code (Text):
    grep -rn 'location \/ {' /usr/local/nginx/conf/conf.d
    
     
  13. Jon Snow

    Jon Snow Active Member

    156
    25
    28
    Jun 30, 2017
    Ratings:
    +30
    Local Time:
    10:29 PM
    Nginx 1.13.4
    MariaDB 10.1.26
    This is line 70 :
    Code (Text):
    70    location / {
     
  14. Jon Snow

    Jon Snow Active Member

    156
    25
    28
    Jun 30, 2017
    Ratings:
    +30
    Local Time:
    10:29 PM
    Nginx 1.13.4
    MariaDB 10.1.26
    Code (Text):
    # grep -rn 'location \/ {' /usr/local/nginx/conf/conf.d
    /usr/local/nginx/conf/conf.d/domain.com.ssl.conf:70:  location / {
    /usr/local/nginx/conf/conf.d/virtual.conf:25:            location / {
    /usr/local/nginx/conf/conf.d/domain.com.conf:33:  location / {
    /usr/local/nginx/conf/conf.d/demodomain.com.conf:22:            location / {
    
     
  15. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    strange then that all looks good unless you have missing ending curly brackets } somewhere in one of your vhosts

    what's contents of /usr/local/nginx/conf/conf.d/domain.com.conf like ?
     
  16. Jon Snow

    Jon Snow Active Member

    156
    25
    28
    Jun 30, 2017
    Ratings:
    +30
    Local Time:
    10:29 PM
    Nginx 1.13.4
    MariaDB 10.1.26
    Code (Text):
    # Centmin Mod Getting Started Guide
    # must read http://centminmod.com/getstarted.html
    
    # redirect from non-www to www
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    # server {
    #            listen   80;
    #            server_name domain.com;
    #            return 301 $scheme://www.domain.com$request_uri;
    #       }
    
    server {
      server_name domain.com www.domain.com;
    
    # ngx_pagespeed & ngx_pagespeed handler
    # include /usr/local/nginx/conf/pagespeed.conf;
    # include /usr/local/nginx/conf/pagespeedhandler.conf;
    # include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      # add_header X-Frame-Options SAMEORIGIN;
      # add_header X-Xss-Protection "1; mode=block" always;
      # add_header X-Content-Type-Options "nosniff" always;
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/domain.com/log/access.log combined buffer=256k flush=5m;
      error_log /home/nginx/domains/domain.com/log/error.log;
    
      root /home/nginx/domains/domain.com/public;
    
      location / {
        # Wordpress Permalinks
        try_files $uri $uri/ /index.php?q=$request_uri;
    
        include /usr/local/nginx/conf/wpsecure.conf;
        include /usr/local/nginx/conf/wpnocache.conf;
      }
    
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/php.conf;
      include /usr/local/nginx/conf/drop.conf;
      # include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
    
     
  17. eva2000

    eva2000 Administrator Staff Member

    30,161
    6,785
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,136
    Local Time:
    11:29 AM
    Nginx 1.13.x
    MariaDB 5.5
    that looks good too

    lets extent grep search one level above at /usr/local/nginx/conf/
    Code (Text):
    grep -rn 'location \/ {' /usr/local/nginx/conf/
    
     
  18. Jon Snow

    Jon Snow Active Member

    156
    25
    28
    Jun 30, 2017
    Ratings:
    +30
    Local Time:
    10:29 PM
    Nginx 1.13.4
    MariaDB 10.1.26
    Code (Text):
    # grep -rn 'location \/ {' /usr/local/nginx/conf/conf.d
    /usr/local/nginx/conf/conf.d/domain.com.ssl.conf:70:  location / {
    /usr/local/nginx/conf/conf.d/virtual.conf:25:            location / {
    /usr/local/nginx/conf/conf.d/domain.com.conf:33:  location / {
    /usr/local/nginx/conf/conf.d/demodomain.com.conf:22:            location / {
    You have new mail in /var/spool/mail/root
    
    [00:54][root@hostname.domain.com ~]# grep -rn 'location \/ {' /usr/local/nginx/conf/
    /usr/local/nginx/conf/nginx.conf.default:43:        location / {
    /usr/local/nginx/conf/nginx.conf.default:89:    #    location / {
    /usr/local/nginx/conf/nginx.conf.default:111:    #    location / {
    /usr/local/nginx/conf/autoprotect/domain.com/autoprotect-domain.com.conf:24:location / {
    /usr/local/nginx/conf/conf.d/domain.com.ssl.conf:70:  location / {
    /usr/local/nginx/conf/conf.d/virtual.conf:25:            location / {
    /usr/local/nginx/conf/conf.d/domain.com.conf:33:  location / {
    /usr/local/nginx/conf/conf.d/demodomain.com.conf:22:            location / {
    
    
     
  19. Sunka

    Sunka Active Member

    917
    240
    43
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +388
    Local Time:
    3:29 AM
    Nginx 1.13.3
    MariaDB 10.1.24
    You have not open/closed bracket at the end of file
    My bad. I copy paste just part of file
     
  20. Jon Snow

    Jon Snow Active Member

    156
    25
    28
    Jun 30, 2017
    Ratings:
    +30
    Local Time:
    10:29 PM
    Nginx 1.13.4
    MariaDB 10.1.26
    Pasted the comments of the first command too but you can see it after "[00:54][root@hostname.domain.com ~]# grep -rn 'location \/ {' /usr/local/nginx/conf/".
    You have to scroll down to see it in the code bb code - /usr/local/nginx/conf/conf.d/domain.com.conf