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 Member

    139
    15
    18
    Apr 21, 2019
    Ratings:
    +29
    Local Time:
    8:00 PM
    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

    44,186
    10,074
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,572
    Local Time:
    1:00 AM
    Nginx 1.17.x
    MariaDB 5.5/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 Member

    139
    15
    18
    Apr 21, 2019
    Ratings:
    +29
    Local Time:
    8:00 PM
    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

    44,186
    10,074
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,572
    Local Time:
    1:00 AM
    Nginx 1.17.x
    MariaDB 5.5/10.x
    put in domain vhost

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

    skringjer Member

    139
    15
    18
    Apr 21, 2019
    Ratings:
    +29
    Local Time:
    8:00 PM
    Okay thank you, everything is clear now.