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

    170
    22
    18
    Apr 21, 2019
    Ratings:
    +37
    Local Time:
    5:30 AM
    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

    47,833
    10,908
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,945
    Local Time:
    10:30 AM
    Nginx 1.21.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 Premium Member Premium Member

    170
    22
    18
    Apr 21, 2019
    Ratings:
    +37
    Local Time:
    5:30 AM
    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

    47,833
    10,908
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +16,945
    Local Time:
    10:30 AM
    Nginx 1.21.x
    MariaDB 10.x
    put in domain vhost

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

    skringjer Premium Member Premium Member

    170
    22
    18
    Apr 21, 2019
    Ratings:
    +37
    Local Time:
    5:30 AM
    Okay thank you, everything is clear now.