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告诉它哪个页面在外部显示,然后只是传递错误编号的脚本.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值