4

I've already read that : how to remove location block from $uri in nginx configuration?

but is there a way to strip the location blocks's prefix from the $fastcgi_script_name without using regex ?

for example :

location /foo/ {
        access_log  /var/log/nginx/access-truc.log  FOO;
        alias          /srv/http/php;
        fastcgi_pass   fpm;
        fastcgi_index  index.php;
        include        fastcgi.conf;
}

(note : FOO is a log format to display $fastcgi_script_name)

fastcgi.conf has this line :

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

And I want $fastcgi_script_name set to only bar.php instead of foo/bar.php for the url http://example.com/foo/bar.php

hl037_
  • 267
  • 2
  • 10

2 Answers2

3

I have not found a way using $fastcgi_script_name, but I actually find that extra level of indirection a bit confusing. I now use the following snippet:

server {
    listen      80;
    root        /var/www;
    try_files   $uri $uri/ =404;
    autoindex   on;

    location /openid {
        alias   /opt/openid/www;
        index   index.html index.php;

        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            include /etc/nginx/fastcgi_params;
        }
    }
}

A request to http://host/openid/ will set SCRIPT_FILENAME correctly to /opt/openid/www/index.php.

akvadrako
  • 131
  • 3
1
location /foo/ {
        fastcgi_split_path_info  ^/foo/((.*));
        access_log  /var/log/nginx/access-truc.log  FOO;
        alias          /srv/http/php;
        fastcgi_pass   fpm;
        fastcgi_index  index.php;
        include        fastcgi.conf;
}
Leo Kwok
  • 11
  • 1