100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > php重定向error 将nginx错误重定向到php

php重定向error 将nginx错误重定向到php

时间:2022-10-20 23:45:58

相关推荐

php重定向error 将nginx错误重定向到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设置为off,那么nginx会处理错误.我的下一步是设置一个新的php脚本请求,它将显示错误.这是位置/ errors / code /< code_number>.

说我有以下位置块:

location = /composer.phar

????{

????????返回403;

????}

我想然后重定向到错误页面/ error / code / 403

因此,我在想

error_page 403 = / error / code / 403;

我会为我做这个伎俩,但是我的php脚本仍在提取原始请求 – 我总是显示404页面,因为我的PHP脚本正在获取一个它不知道的位置的请求.我希望nginx告诉它哪个页面在外部显示,然后只是传递错误编号的脚本.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。