Learn about Centmin Mod LEMP Stack today
Register Now

Nginx Nginx Error - [emerg] unknown directive "#"

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by ljseals, Dec 23, 2016.

  1. ljseals

    ljseals Member

    101
    24
    18
    Dec 20, 2016
    Ratings:
    +46
    Local Time:
    12:55 AM
    Greetings, having some issues with my nginx configuration file. I tried numerous times to troubleshoot by adding taking away code to see if it will work. :) That is how newbies do it. Anyway I can not get passed this specific error code. I am using:

    Code (Text):
    [root@srv1 ~]# nginx -v
    nginx version: nginx/1.11.7
    

    The error shows unknown directive "#"?

    Code (Text):
    [root@srv1 ~]# nginx -t
    nginx: [emerg] unknown directive "#" in /usr/local/nginx/conf/conf.d/onthecheap.store.conf:9
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
    


    I suppose that would mean that something is incorrectly commented out but I really do not know. Here is my nginx configuration file.

    Code (Text):
    # Centmin Mod Getting Started Guide
    # must read http://centminmod.com/getstarted.html
    # For HTTP/2 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 {
       server_name onthecheap.store www.onthecheap.store;
        return 302 https://www.onthecheap.store$request_uri;
     }
    
    server {
      listen 443 ssl http2;
      server_name onthecheap.store www.onthecheap.store;
    
            ssl_dhparam /usr/local/nginx/conf/ssl/onthecheap.store/dhparam.pem;
            ssl_certificate      /usr/local/nginx/conf/ssl/onthecheap.store/ssl-unified.crt;
            ssl_certificate_key  /usr/local/nginx/conf/ssl/onthecheap.store/ssl.key;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_session_cache      shared:SSL:10m;
            ssl_session_timeout  10m;
            ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!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;
            add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
            #add_header  X-Content-Type-Options "nosniff";
            #add_header X-Frame-Options DENY;
            # nginx 1.5.9+ or higher
            # http://nginx.org/en/docs/http/ngx_http_spdy_module.html#spdy_headers_comp
            # http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_buffer_size
            # spdy_headers_comp 0;
            # ssl_buffer_size 4k;
    
            # enable ocsp stapling
            resolver 8.8.8.8;
            ssl_stapling on;
            ssl_stapling_verify on;
            ssl_trusted_certificate /usr/local/nginx/conf/ssl/onthecheap.store/ssl-trusted.crt;
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
    
    # 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/onthecheap.store/log/access.log combined buffer=32k;
      error_log /home/nginx/domains/onthecheap.store/log/error.log;
    
      root /home/nginx/domains/onthecheap.store/public;
    
    location / {
      try_files $uri $uri/ @xc5;
       index cart.php index.php;
    }
    
    location @xc5 {
      if ( $uri ~ "^/((([/_a-zA-Z0-9-]+)/)?([_a-zA-Z0-9-]+)/)?([_a-zA-Z0-9-]+)(/?)(\.([_a-zA-Z0-9-]+))?$" ) {
          set $rurl $5;
          set $rlast $4;
          set $rrest $3;
          set $rext $7;
    
          rewrite ^ /cart.php?url=$rurl&last=$rlast&rest=$rrest&ext=$rext last;
       }
    
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/php_xcart.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }


    Up nginx restart I get the code:
    Code (Text):
    [root@srv1 ~]# service nginx restart
    Restarting nginx (via systemctl):  Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
                                                               [FAILED]
    


    Systemctl Status Nginx.service


    Code (Text):
    [root@srv1 ~]# 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 2016-12-22 20:35:48 UTC; 2min 39s ago
         Docs: man:systemd-sysv-generator(8)
      Process: 3368 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=1/FAILURE)
    
    Dec 22 20:35:48 srv1.onthecheap.store systemd[1]: Starting SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server...
    Dec 22 20:35:48 srv1.onthecheap.store nginx[3368]: Starting nginx: nginx: [emerg] unknown directive "#" in /usr/local/nginx/conf/conf.d/onthecheap.store.conf:9
    Dec 22 20:35:48 srv1.onthecheap.store systemd[1]: nginx.service: control process exited, code=exited status=1
    Dec 22 20:35:48 srv1.onthecheap.store nginx[3368]: [FAILED]
    Dec 22 20:35:48 srv1.onthecheap.store systemd[1]: Failed to start SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server.
    Dec 22 20:35:48 srv1.onthecheap.store systemd[1]: Unit nginx.service entered failed state.
    Dec 22 20:35:48 srv1.onthecheap.store systemd[1]: nginx.service failed.
    




    Journalctl -xe

    [root@srv1 ~]# journalctl -xe -- Unit session-20.scope has finished starting up - Pastebin.com

    Thanks in advance. God bless you!
     
    Last edited: Dec 23, 2016
  2. ljseals

    ljseals Member

    101
    24
    18
    Dec 20, 2016
    Ratings:
    +46
    Local Time:
    12:55 AM
    May have something to do with copying and pasting, will retry with nano.
     
  3. PeppaPigKilla

    PeppaPigKilla Member

    43
    12
    8
    Dec 21, 2016
    Ratings:
    +13
    Local Time:
    6:55 AM
    1.11.7
    10.0.28-MariaDB
    It looks like there is a # somewhere it shouldnt be, I copied your conf and highlight all the # and the only 2 that stood out for me are on this line.

    Code:
     # http://nginx.org/en/docs/http/ngx_http_spdy_module.html#spdy_headers_comp
            # http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_buffer_size
    even though the intial line of code is # out, i dont know if the second # on each line is causing an issue.

    Use Sublime text to review your code.

    Im a complete newb at this so i may be wrong, just tried to help.
     
  4. ljseals

    ljseals Member

    101
    24
    18
    Dec 20, 2016
    Ratings:
    +46
    Local Time:
    12:55 AM
    I think I may have fixed it with the Lord's help. As a newb, I am looking to copy and paste text but as I read over these forums you must us Unix utf8. So I downloaded Notepad ++ and went to, Edit-->EOL CONVERSION --> UNIX. That fixed the first error. The second error was I did not rename the ssl.key to the correct key file name. Lastly, I updated the X-Cart code that was given via their help documents. God bless you!
     
    Last edited: Dec 23, 2016
  5. eva2000

    eva2000 Administrator Staff Member

    55,163
    12,249
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,825
    Local Time:
    3:55 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+