Can fastcgi_index be used with multiple filenames?

Ian M. Evans ianevans at
Sat Mar 8 13:01:58 MSK 2008

Igor Sysoev wrote:
> If php root and static root are the same, then you can use following:
>     location / {
>         index   index.shtml   index.php;
>         # static
>     }
>     location \.(php|shtml)$ {
>         fastcgi_pass  ...
>         # fastcgi_index is not needed here at all
>     }

I guess I should never do config changes at 4:42 AM! Luckily, I can just 
"cp oldconfig nginx.conf" and -HUP and the site's back and running while 
I tweak some more.

Currently anything that's not a static file gets passed to an Apache 
backend and run as a PHP file.

So index.php, index.shtml and even extensionless files are PHP files. 
For example, /galleries/123/1 is a php file called galleries that works 
with the /123/1 path info.

I'm moving to fastcgi so I can drop Apache. Right now my test config 
file for fastcgi is doing fine serving the extensionless PHP files but 
giving me "No input file specified on the .php and .shtml files. I added 
your suggestions above but I must have broken something somewhere else. 
Here's a snippet of my fastcgi config test:

server {
listen 80;
root /usr/local/apache/htdocs;
index index.shtml index.php;
error_page 404 /dhe404.shtml;

location /stub_status {
stub_status on;
access_log off;
deny all;

location / {
root /usr/local/apache/htdocs;
index index.shtml index.php;
include /usr/local/nginx/conf/fastcgi.conf;

location \.(php|shtml)$ {
include /usr/local/nginx/conf/fastcgi.conf;
location ~* 
root /usr/local/apache/htdocs;
error_page 403 /dhe403.shtml;
valid_referers none blocked * ;
if ($invalid_referer) {
return 403;

location ~* ^.+\.(gif|js)$ {
root /usr/local/apache/htdocs;

The included fastcgi.conf contains:
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
fastcgi_param PATH_INFO       $fastcgi_script_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

As I said, the extensionless files are being run through fastcgi just 
fine, so I'm assuming I just put something in the wrong order.


More information about the nginx mailing list