nginx执行php404,让Nginx调用PHP文件来处理php-fpm下的404错误

我正在尝试配置Nginx将所有404发送到php文件以进行进一步处理.我没有工作.使用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频道中的善良人士,他们花了一些时间向我展示正确的方向.

标签:nginx,php

来源: https://codeday.me/bug/20190515/1105219.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值