ceo779382
By:
ceo779382

NginX - php location block wrongfully takes request

February 4, 2018 143 views
Nginx Ubuntu 16.04

I have a php script to be executed outsite of my server root. As far as I read I need to define a location block with a different root to execute the php correctly.

Problem: NginX always takes the last php location block from my configuration and NOT the nested one under my location /de/forums nor the location /de/forums/(.+.php).

What am I doing wrong? How can I convince nginx to take a location block with the correct root defined?

As far as I understood the hierarchy - the more specific block should be used... please help!

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name domain.com;

    root /var/www/domain.com/html;
    index index.php;


    location ^~ /de/forums {
            root /var/www/domain.com/;
            #alias /var/www/domain.com/de/forums/;

            index index.php index.html index.htm;
            try_files $uri $uri/ /de/forums/index.php?$uri&$args;


                location ~* \.php(/|$) {
                    fastcgi_pass  unix:/var/run/php/php7.2-fpm.sock;
                    fastcgi_split_path_info ^(.+\.php)(/.*)$;
                    include fastcgi.conf;   
                    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                }
    }

    location ^~ /de/forums/(.+\.php) { 
        root /var/www/domain.com/;     
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        include fastcgi.conf;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    }   



    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include fastcgi.conf;
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;

    }

}
Be the first one to answer this question.