Welcome to Centmin Mod Community
Become a Member

Nginx Upgrading Nginx via Menu Option 4 broke it

Discussion in 'Install & Upgrades or Pre-Install Questions' started by top, Jul 31, 2021.

  1. top

    top New Member

    10
    9
    3
    Jun 2, 2017
    Ratings:
    +9
    Local Time:
    7:38 AM
    • CentOS Version: CentOS 7 64bit
    • Centmin Mod Version Installed: 123.09beta01
    • Nginx Version Installed: 1.21.0 -> upgraded to 1.21.1
    • The only line in the persistent config I have is LETSENCRYPT_DETECT='y'
    I updated the Centmin code base, and later updated Nginx from 1.20.0 to 1.21.1, after following the prompt that there's a new version available. After I upgraded the nginx version, it broke all the sites on my server. I tried downgrading to 1.21.0 but it didn't fix the issue.

    nginx -t outputs:

    Code (Text):
    nginx: [emerg] duplicate location "/" in /usr/local/nginx/conf/conf.d/domain.com.ssl.conf:69
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
    


    This is the file's content starting with line 69:
    Code (Text):
      location / {
      include /usr/local/nginx/conf/503include-only.conf;
    
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # for wordpress super cache plugin
      try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?q=$uri&$args;
    
      # for wp cache enabler plugin
      #try_files $cache_enabler_uri_webp $cache_enabler_uri $uri $uri/ $custom_subdir/index.php?$args;
    
      # Wordpress Permalinks
      #try_files $uri $uri/ /index.php?q=$uri&$args;
    
      # Nginx level redis Wordpress
      # https://community.centminmod.com/posts/18828/
      #try_files $uri $uri/ /index.php?$args;
    
      }
    


    I tried using older nginx conf backups from the auto backups. I tried upgrading PHP too. Both didn't solve the issue. I can't start/restart nginx, because of the same issue.

    EDIT:

    Disabling autoprotect.sh fixed the issue. Beta Branch - autoprotect.sh - apache .htaccess check & migration to nginx deny all

    So what's the long-term solution here? Should I delete all .htaccess files I find and enable autoprotect? As far as I checked, there isn't any important stuff in the htaccess files. Some of the plugins I use automatically add a .htaccess file, so they may add it again even if I delete it

     
    Last edited: Jul 31, 2021
  2. eva2000

    eva2000 Administrator Staff Member

    47,292
    10,703
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,628
    Local Time:
    3:38 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    what's the contents of your /usr/local/nginx/conf/autoprotect/domain.com/autoprotect-domain.com.conf include file ?

    for posting code or output from commands to keep the formatting, you might want to use CODE tags for code How to use forum BBCODE code tags :)
     
  3. top

    top New Member

    10
    9
    3
    Jun 2, 2017
    Ratings:
    +9
    Local Time:
    7:38 AM
    Here it is:
    Code (Text):
    # /home/nginx/domains/domain.com/public/wp-content/plugins/akismet
    
    location /wp-content/plugins/akismet/ {
      location ~ ^/wp-content/plugins/akismet/(.+/)?(form|akismet)\.(css|js)$ { allow all; expires 30d;}
      location ~ ^/wp-content/plugins/akismet/(.+/)?(.+)\.(png|gif)$ { allow all; expires 30d;}
      location ~* /wp-content/plugins/akismet/.*\.php$ {
        include /usr/local/nginx/conf/php.conf;
        allow 127.0.0.1;
        deny all;
      }
    }
    
    # /home/nginx/domains/domain.com/public/wp-content/uploads/mainwp/backup
    location ~* ^/wp-content/uploads/mainwp/backup/ { allow 127.0.0.1; deny all; }
    # /home/nginx/domains/domain.com/public/wp-content/updraft
    location ~* ^/wp-content/updraft/ { allow 127.0.0.1; deny all; }
    # https://community.centminmod.com/posts/35394/
    # /home/nginx/domains/domain.com/public/wp-content/wflogs
    
    location /wp-content/wflogs/ {
      location ~ ^/wp-content/wflogs/(.+/)?(.+)\.(js)$ { allow all; expires 30d; }
      location ~ ^/wp-content/wflogs/(.+/)?(.+)\.(css)$ { allow all; expires 30d; }
      location ~ ^/wp-content/wflogs/(.+/)?(.+)\.(gif|jpe?g|png|webp|eot|svg|ttf|woff|woff)$ { allow all; expires 30d; }
      location ~ ^/wp-content/wflogs/(.+/)?(.+)\.(php|cgi|pl|php3|php4|php5|php6|phtml|shtml)$ { allow 127.0.0.1; deny all; }
    }
    
    # https://community.centminmod.com/posts/35394/
    # /home/nginx/domains/domain.com/public
    
    location / {
      location ~ ^/(.+/)?(.+)\.(js)$ { allow all; expires 30d; }
      location ~ ^/(.+/)?(.+)\.(css)$ { allow all; expires 30d; }
      location ~ ^/(.+/)?(.+)\.(gif|jpe?g|png|webp|eot|svg|ttf|woff|woff)$ { allow all; expires 30d; }
      location ~ ^/(.+/)?(.+)\.(php|cgi|pl|php3|php4|php5|php6|phtml|shtml)$ { allow 127.0.0.1; deny all; }
    }
    
    
     
  4. eva2000

    eva2000 Administrator Staff Member

    47,292
    10,703
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,628
    Local Time:
    3:38 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    looks like the last entry populated is one causing the issue
    Code (Text):
    location / {
      location ~ ^/(.+/)?(.+)\.(js)$ { allow all; expires 30d; }
      location ~ ^/(.+/)?(.+)\.(css)$ { allow all; expires 30d; }
      location ~ ^/(.+/)?(.+)\.(gif|jpe?g|png|webp|eot|svg|ttf|woff|woff)$ { allow all; expires 30d; }
      location ~ ^/(.+/)?(.+)\.(php|cgi|pl|php3|php4|php5|php6|phtml|shtml)$ { allow 127.0.0.1; deny all; }
    }
    

    Best way to prevent detection of .htaccess at web root of / is outlined at Beta Branch - autoprotect.sh - apache .htaccess check & migration to nginx deny all
    So create a .autoprotect-bypass file at web root / which would be /home/nginx/domains/yourdomain.com/public/.autoprotect-bypass and then re-run the cronjob script manually at /usr/local/src/centminmod/tools/autoprotect.sh to re-populate
    /usr/local/nginx/conf/autoprotect/domain.com/autoprotect-domain.com.conf include file for your domain and re-inspecting /usr/local/nginx/conf/autoprotect/domain.com/autoprotect-domain.com.conf include file so now have that last web root / location context entry removed
     
  5. top

    top New Member

    10
    9
    3
    Jun 2, 2017
    Ratings:
    +9
    Local Time:
    7:38 AM
    That fixed it. Thanks!