我正在尝试配置nginx将所有404发送到php文件以进行futher处理。我没有工作。使用try_files,我获得了默认的404,没有try_files,我没有指定输入文件。这就是我到目前为止的:
server {
listen 192.168.100.44:80;
location / {
index index.html;
}
root /var/www/test.example.com;
error_page 404 /404.php;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
#try_files $uri = 404;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
答案是添加行: fastcgi_intercept_errors on;
然后,为了处理404,并可能从PHP脚本返回其他状态代码: error_page 404/404.php; 必须简单地更改为: error_page 404 =/404.php;
归功于Nginx IRC频道中的善良人士,他们花了一些时间向我展示正确的方向。