我的目标是将Nginx中的任何错误(即404,405等…)重定向到位于index.PHP的我的PHP脚本.
`
server {
root /usr/share/Nginx/TradeLog/www/;
index index.PHP index.html index.htm default.html default.htm;
# Make site accessible from http://localhost/
server_name localhost;
server_name_in_redirect off;
fastcgi_intercept_errors on;
error_page 403 404 /index.PHP/;
location / {
try_files $uri $uri/ /index.PHP?$args;
}
location ~* \.PHP$
{
fastcgi_split_path_info ^(.+\.PHP)(/.+)$;
fastcgi_pass unix:/var/run/PHP5-fpm.sock;
include fastcgi_params;
fastcgi_read_timeout 600; # Set fairly high for debugging
fastcgi_index index.PHP;
}
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)${
expires max;
}
}
`
但是,当我尝试这个时,我遇到了一个Nginx 404错误.我在这做错了什么?
编辑
我发现如果我将fastcgi_intercept_errors设置为off,那么Nginx会处理错误.我的下一步是设置一个新的PHP脚本请求,它将显示错误.这是位置/ errors / code /< code_number>.
说我有以下位置块:
location = /composer.phar
{
返回403;
}
我想然后重定向到错误页面/ error / code / 403
因此,我在想
error_page 403 = / error / code / 403;
我会为我做这个伎俩,但是我的PHP脚本仍在提取原始请求 – 我总是显示404页面,因为我的PHP脚本正在获取一个它不知道的位置的请求.我希望Nginx告诉它哪个页面在外部显示,然后只是传递错误编号的脚本.
解决方法:
我想你应该替换:
error_page 403 404 /index.PHP/;
有:
error_page 403 404 /index.PHP;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。