Learn about Centmin Mod LEMP Stack today
Register Now

Nginx Why Does Nginx Rewrite Rules Work Differently In Centmin

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by skringjer, May 22, 2020.

  1. skringjer

    skringjer NoobMaster69

    208
    26
    28
    Apr 21, 2019
    Ratings:
    +43
    Local Time:
    4:17 AM
    Nginx 1.21.6
    MariaDB 10.3.x
    Hi everyone, so i wanted to know why does the nginx rewrite rules modifications to have them work in centmin, for example the below rewrite rule does not work, if i put it in my domains vhost conf.

    However, it works fine on Lemp stack or vestacp or cpanel. I had other rules like this which @eva2000 modified to fix them


    Code:
    # nginx webdav rules
    # allow for paths ending with forward slashes
    rewrite ^/app/(.*)/ /plugins/webdav/site/control/$1 last;
    rewrite ^/app/(.*) /plugins/webdav/site/control/$1 last;
    # all webdav requests
    location /plugins/webdav/site/control/ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        gzip off;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        include        fastcgi_params;
    }
     
  2. eva2000

    eva2000 Administrator Staff Member

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    9:17 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    it's because the default Centmin Mod vhost php.conf include file takes care of all PHP requests
    Code (Text):
    include /usr/local/nginx/conf/php.conf;

    with a location match like
    Code (Text):
    location ~ [^/]\.php(/|$) {
    
    }

    You might be able to make it work if you change

    from
    Code (Text):
    location /plugins/webdav/site/control/ {
       fastcgi_split_path_info ^(.+\.php)(/.+)$;
       fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
       gzip off;
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       include        fastcgi_params;
    }
    

    to
    Code (Text):
    location /plugins/webdav/site/control/(.+\.php)(/.+)$ {
       fastcgi_split_path_info ^(.+\.php)(/.+)$;
       fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
       gzip off;
       fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
       include        fastcgi_params;
    }
    
     
  3. skringjer

    skringjer NoobMaster69

    208
    26
    28
    Apr 21, 2019
    Ratings:
    +43
    Local Time:
    4:17 AM
    Nginx 1.21.6
    MariaDB 10.3.x
    Ohh okay now i understand, And its a better way too.

    And should i put the new rules in php.conf or the domains vhost

    And also you didnt mention anything about this

    rewrite ^/app/(.*)/ /plugins/webdav/site/control/$1 last;
    rewrite ^/app/(.*) /plugins/webdav/site/control/$1 last;
     
  4. eva2000

    eva2000 Administrator Staff Member

    53,530
    12,134
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,677
    Local Time:
    9:17 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    put in domain vhost

    the rewrite rules redirect to the suggested location match anyway
     
  5. skringjer

    skringjer NoobMaster69

    208
    26
    28
    Apr 21, 2019
    Ratings:
    +43
    Local Time:
    4:17 AM
    Nginx 1.21.6
    MariaDB 10.3.x
    Okay thank you, everything is clear now.