Want more timely Centmin Mod News Updates?
Become a Member

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 Premium Member

    203
    24
    18
    Apr 21, 2019
    Ratings:
    +40
    Local Time:
    12:19 PM
    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

    50,897
    11,797
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,252
    Local Time:
    5:19 PM
    Nginx 1.25.x
    MariaDB 10.x
    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 Premium Member

    203
    24
    18
    Apr 21, 2019
    Ratings:
    +40
    Local Time:
    12:19 PM
    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

    50,897
    11,797
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,252
    Local Time:
    5:19 PM
    Nginx 1.25.x
    MariaDB 10.x
    put in domain vhost

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

    skringjer NoobMaster69 Premium Member

    203
    24
    18
    Apr 21, 2019
    Ratings:
    +40
    Local Time:
    12:19 PM
    Nginx 1.21.6
    MariaDB 10.3.x
    Okay thank you, everything is clear now.