Can fastcgi_index be used with multiple filenames?

Ian M. Evans ianevans at digitalhit.com
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;
server_name www.example.com;
index index.shtml index.php;
error_page 404 /dhe404.shtml;

location /stub_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}

location / {
root /usr/local/apache/htdocs;
index index.shtml index.php;
include /usr/local/nginx/conf/fastcgi.conf;
fastcgi_pass 127.0.0.1:10004;
}

location \.(php|shtml)$ {
include /usr/local/nginx/conf/fastcgi.conf;
fastcgi_pass 127.0.0.1:10004;
}
		
location ~* 
^.+\.(jpg|jpeg|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mov)$ 
{
root /usr/local/apache/htdocs;
error_page 403 /dhe403.shtml;
valid_referers none blocked *.example.com example.com ;
if ($invalid_referer) {
return 403;
}
}

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

The included fastcgi.conf contains:
#fastcgi.conf
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.

Thanks!





More information about the nginx mailing list