nginx从别名目录访问php时给予404

我正在尝试从apache迁移到nginx。 我托pipe的PHP网站需要访问共享库,这是一个别名目录。 下面是我想出的configuration。 HTML文件工作正常,但PHP文件给404。我已经通读,并尝试了大多数(如果不是全部)的类似问题的答案,没有任何成功。 任何暗示什么可能导致这个问题在我的情况?

location /wtlib/ { alias /var/www/shared/wtlib_4/; index index.php; } location ~ /wtlib/.*\.php$ { alias /var/www/shared/wtlib_4/; try_files $uri =404; if ($fastcgi_script_name ~ /wtlib(/.*\.php)$) { set $valid_fastcgi_script_name $1; } fastcgi_pass 127.0.0.1:9013; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/shared/wtlib_4$valid_fastcgi_script_name; fastcgi_param REDIRECT_STATUS 200; include /etc/nginx/fastcgi_params; } 

谢谢大家!

更新:以下似乎工作正常:

 location /wtlib/ { alias /usr/share/php/wtlib_4/; location ~* .*\.php$ { try_files $uri @php_wtlib; } location ~* \.(html|htm|js|css|png|jpg|jpeg|gif|ico|pdf|zip|rar|air)$ { expires 7d; access_log off; } } location @php_wtlib { if ($fastcgi_script_name ~ /wtlib(/.*\.php)$) { set $valid_fastcgi_script_name $1; } fastcgi_pass $byr_pass; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/php/wtlib_4$valid_fastcgi_script_name; fastcgi_param REDIRECT_STATUS 200; include /etc/nginx/fastcgi_params; } 

你的行try_files $uri =404; 是原因,但你可以改善你的configuration:

 server { # other code ... index index.php; location /wtlib/ { alias /var/www/shared/wtlib_4/; location ~* .*\php$ { try_files $uri @php; } } location @php { fastcgi_pass 127.0.0.1:9013; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param REDIRECT_STATUS 200; include /etc/nginx/fastcgi_params; } }