Learn about Centmin Mod LEMP Stack today
Register Now

Xenforo Xenforo 2 Nginx rewrites Error

Discussion in 'Forum software usage' started by Itworx4me, Jan 15, 2018.

  1. Itworx4me

    Itworx4me Premium Member Premium Member

    67
    6
    8
    Mar 14, 2017
    Ratings:
    +7
    Local Time:
    5:53 AM
    Xenforo 2 Nginx rewrites Error

    They are saying that the domain.com.conf file doesn't have server blocks to allow the rewrites. How do I fix this ?

    Thanks,
    Itworx4me
     
  2. eva2000

    eva2000 Administrator Staff Member

    32,251
    7,165
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,892
    Local Time:
    11:53 PM
    Nginx 1.13.x
    MariaDB 5.5
  3. Sunka

    Sunka Well-Known Member

    949
    250
    63
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +411
    Local Time:
    2:53 PM
    Nginx 1.13.3
    MariaDB 10.1.24
    I am on xf2 from New year and everything about that is working fine
     
  4. Itworx4me

    Itworx4me Premium Member Premium Member

    67
    6
    8
    Mar 14, 2017
    Ratings:
    +7
    Local Time:
    5:53 AM
  5. Itworx4me

    Itworx4me Premium Member Premium Member

    67
    6
    8
    Mar 14, 2017
    Ratings:
    +7
    Local Time:
    5:53 AM
    Here is my domain.com.conf file

    Code:
    # 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-Content-Type-Options "nosniff" always;
    
      #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 main_ext buffer=256k flush=60m;
    
      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 / {
    
        try_files $uri $uri/ /index.php?$uri&$args;
    
        index index.php index.html;
    
      }
    
    
      location /install/data/ {
    
        internal;
    
        allow 127.0.0.1;
    
        allow 0.0.0.0.0.0
    
        deny all;
    
      }
    
    
      location /install/templates/ {
    
        internal;
    
        allow 127.0.0.1;
    
        allow 0.0.0.0.0
    
        deny all;
    
      }
    
    
      location /internal_data/ {
    
        internal;
    
        allow 127.0.0.1;
    
        allow 0.0.0.0.0
    
        deny all;
    
      }
    
    
      location /src/ {
    
        internal;
    
        allow 127.0.0.1;
    
        allow 0.0.0.0.0
    
        deny all;
    
      }
    
    
      location ~ \.php$ {
    
        try_files $uri =404;
    
        fastcgi_pass    127.0.0.1:9000;
    
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    
        include         fastcgi_params;
    
      }
    
    
      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;
    
    
      # Enable for vBulletin usage WITHOUT vbSEO installed
    
      # More example Nginx vhost configurations at
    
      # http://centminmod.com/nginx_configure.html
    
      #try_files            $uri $uri/ /index.php;
    
    
      }
    
    
      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;
    }
    

    Any help would be much appreciated

    Itworx4me
     
    Last edited: Jan 15, 2018
  6. Jon Snow

    Jon Snow Active Member

    260
    39
    28
    Jun 30, 2017
    Ratings:
    +59
    Local Time:
    9:53 AM
    Nginx 1.13.4
    MariaDB 10.1.26
    Remove :
    Code (Text):
     location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include         fastcgi_params;
      }

    And merge :
    Code (Text):
      location / {
        try_files $uri $uri/ /index.php?$uri&$args;
        index index.php index.html;
      }
    
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    }
    
     
  7. eva2000

    eva2000 Administrator Staff Member

    32,251
    7,165
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,892
    Local Time:
    11:53 PM
    Nginx 1.13.x
    MariaDB 5.5
    yes remove
    Code (Text):
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include         fastcgi_params;
      }
    

    and remove duplicate location / context
    Code (Text):
      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;
    
      # Enable for vBulletin usage WITHOUT vbSEO installed
      # More example Nginx vhost configurations at
      # http://centminmod.com/nginx_configure.html
      #try_files            $uri $uri/ /index.php;
    
      }
    

    as you already had one
    Code (Text):
      location / {
        try_files $uri $uri/ /index.php?$uri&$args;
        index index.php index.html;
      }
    

    end result is something like
    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-Content-Type-Options "nosniff" always;
      #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 main_ext buffer=256k flush=60m;
      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 / {
        try_files $uri $uri/ /index.php?$uri&$args;
        index index.php index.html;
      }
    
      location /install/data/ {
        internal;
        allow 127.0.0.1;
        allow 0.0.0.0.0.0
        deny all;
      }
    
      location /install/templates/ {
        internal;
        allow 127.0.0.1;
        allow 0.0.0.0.0
        deny all;
      }
    
      location /internal_data/ {
        internal;
        allow 127.0.0.1;
        allow 0.0.0.0.0
        deny all;
      }
    
      location /src/ {
        internal;
        allow 127.0.0.1;
        allow 0.0.0.0.0
        deny all;
      }
    
      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; 
    }
    
     
    • Like Like x 1
  8. Itworx4me

    Itworx4me Premium Member Premium Member

    67
    6
    8
    Mar 14, 2017
    Ratings:
    +7
    Local Time:
    5:53 AM
    Thank you at @eva2000 for your help. I was finally able to get it to work.

    I do have a question though. I used the backup /usr/local/nginx/conf/conf.d/newdomain.com.conf.bak that was created when I setup centmin. I torpedoed the newdomain.com.conf. Reason why I reverted back to the backup. Why does it have code that is repeated in there for the Nginx rewrites? Also there was no mention of deleting such code in the instructions. One of the biggest reasons for not getting this to work in the first place.

    Thanks to everyone who chimed in here to help me. Much aprreciated
    Itworx4me
     
  9. eva2000

    eva2000 Administrator Staff Member

    32,251
    7,165
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,892
    Local Time:
    11:53 PM
    Nginx 1.13.x
    MariaDB 5.5
    it's assumed you know or have some understanding of nginx vhost/rewrite and contexts

    While Centmin Mod Nginx structure is different, these guides provide basics for understanding the structure i.e. this is the location context for web root /
    Code (Text):
    location / {
      yoursettings...
    }
    

    and you'd only have one of those within server{} context per vhost - no duplicates
     
    • Informative Informative x 1
  10. Itworx4me

    Itworx4me Premium Member Premium Member

    67
    6
    8
    Mar 14, 2017
    Ratings:
    +7
    Local Time:
    5:53 AM
    I am getting this error when I try and use the above code with my new server:
    Code (Text):
    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.


    Any ideas?

    Thanks,
    Itworx4me
     
    Last edited: Feb 2, 2018
  11. Itworx4me

    Itworx4me Premium Member Premium Member

    67
    6
    8
    Mar 14, 2017
    Ratings:
    +7
    Local Time:
    5:53 AM
    ran this code:
    Code (Text):
    nginx -t
    

    Got this result:
    Code (Text):
    nginx: [emerg] duplicate location "/src/" in /usr/local/nginx/conf/conf.d/domain.com.conf:70
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
    


    Hope this helps
    Itworx4me
     
  12. Itworx4me

    Itworx4me Premium Member Premium Member

    67
    6
    8
    Mar 14, 2017
    Ratings:
    +7
    Local Time:
    5:53 AM
    I don't see the duplicate:
    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-Content-Type-Options "nosniff" always;
      #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 main_ext buffer=256k flush=60m;
      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 / {
        try_files $uri $uri/ /index.php?$uri&$args;
        index index.php index.html;
      }
    
      location /install/data/ {
        internal;
        allow 127.0.0.1;
        allow IP;
        deny all;
      }
    
      location /install/templates/ {
        internal;
        allow 127.0.0.1;
        allow IP;
        deny all;
      }
    
      location /internal_data/ {
        internal;
        allow 127.0.0.1;
        allow IP;
        deny all;
      }
    
      location /src/ {
        internal;
        allow 127.0.0.1;
        allow IP;
        deny all;
      }
    
    
      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;
    
      }
    
    
    
     
    Last edited: Feb 3, 2018
  13. eva2000

    eva2000 Administrator Staff Member

    32,251
    7,165
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,892
    Local Time:
    11:53 PM
    Nginx 1.13.x
    MariaDB 5.5
    check your autoprotect include file contents as /src directory might have .htaccess files
    Code (Text):
    include /usr/local/nginx/conf/autoprotect/Domain.com/autoprotect-Domain.com.conf;
    


    If on Centmin Mod 123.09beta01, you may have ran into the new tools/autoprotect.sh cronjob feature outlined at Beta Branch - autoprotect.sh - apache .htaccess check & migration to nginx deny all | Centmin Mod Community You uploaded scripts may have .htaccess deny from all type files in their directories which may need bypassing autoprotect. It's a security feature that no other nginx based stack has as far as I know :)

    So instead, all .htaccess 'deny from all' detected directories now get auto generated Nginx equivalent location match and deny all setups except if you want to manually bypass the directory from auto protection via a .autoprotect-bypass file - details below here.

    You can read a few threads below on how autoprotect.sh may have caught some folks web apps falsely and the workarounds or improvements made to autoprotect.sh with the help of users feedback and troubleshooting.
     
  14. Itworx4me

    Itworx4me Premium Member Premium Member

    67
    6
    8
    Mar 14, 2017
    Ratings:
    +7
    Local Time:
    5:53 AM
    So the solution is this?
    Code (Text):
    touch /home/nginx/domains/newdomain.com/public/src/.autoprotect-bypass


    Thanks,
    Itworx4me
     
  15. Itworx4me

    Itworx4me Premium Member Premium Member

    67
    6
    8
    Mar 14, 2017
    Ratings:
    +7
    Local Time:
    5:53 AM
    This is the output from that file:
    Code (Text):
    # https://community.centminmod.com/posts/35394/
    # /home/nginx/domains/Domain.com/public/src
    
    location /src/ {
      location ~ ^/src/(.+/)?(.+)\.(js)$ { allow all; expires 30d; }
      location ~ ^/src/(.+/)?(.+)\.(css)$ { allow all; expires 30d; }
      location ~ ^/src/(.+/)?(.+)\.(gif|jpe?g|png|webp|eot|svg|ttf|woff|woff)$ { allow all; expires 30d; }
      location ~ ^/src/(.+/)?(.+)\.(php|cgi|pl|php3|php4|php5|php6|phtml|shtml)$ { allow 127.0.0.1; deny all; }
    }
    

    I am thinking that I have to remove this from the file. Then add the autoprotect-bypass to the src file?

    Thanks,
    Itworx4me
     
  16. Itworx4me

    Itworx4me Premium Member Premium Member

    67
    6
    8
    Mar 14, 2017
    Ratings:
    +7
    Local Time:
    5:53 AM
    Just making sure this was the correct way to handle this. I ended up trying this and it worked. Just not sure if it was the correct way...

    Thanks,
    Itworx4me