[英]Redirect nginx errors to php
我的目标是将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 on
为off
,那么nginx会处理错误。 我的下一步是设置一个新的php脚本请求,它将显示错误。 这是位置/errors/code/<code_number>
。
说我有以下位置块:
location = /composer.phar { return 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;
额外/重定向到目录,而不是文件。 其余配置似乎没问题。
这是工作error_page 404 = /index.php;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.