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
locationdirective) has noindexdirective, then thelocationdirective will never match and thefastcgi_indexdirective is useless.If you have a line like this on your configuration
then a request to
/will create an internal redirect to/index.php, thelocationwill match and fastcgi will be called. php-fpm will need aSCRIPT_FILENAMEparameter that points to the file being executed. Normally, the configuration looks something like this:$fastcgi_script_namecontains the name of the matched script, sofastcgi_indexis ignored.There is at least one instance where
fastcgi_indexis useful and used: when nginx and php-fpm are on different servers and nginx can't match the index.php file.