On many sites can be found this nginx location
block :
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000
fastcgi_index index.php
...
}
Given the official documentation of fastcgi_index
, it seems like it is used when requests end with /
. However, it doesn't match the regular expression of the location
block above? Am I missing something about the fastcgi_index
directive?
You are right, if your nginx configuration (outside the
location
directive) has noindex
directive, then thelocation
directive will never match and thefastcgi_index
directive is useless.If you have a line like this on your configuration
then a request to
/
will create an internal redirect to/index.php
, thelocation
will match and fastcgi will be called. php-fpm will need aSCRIPT_FILENAME
parameter that points to the file being executed. Normally, the configuration looks something like this:$fastcgi_script_name
contains the name of the matched script, sofastcgi_index
is ignored.There is at least one instance where
fastcgi_index
is useful and used: when nginx and php-fpm are on different servers and nginx can't match the index.php file.