gpt4 book ai didi

nginx - php-fpm下获取Nginx调用PHP文件处理404错误

转载 作者:可可西里 更新时间:2023-11-01 13:50:44 26 4
gpt4 key购买 nike

我正在尝试配置 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 开启;

然后,为了处理 404 并可能从 PHP 脚本返回不同的状态代码: error_page 404/404.php;必须简单地更改为: error_page 404 =/404.php;

感谢 Nginx IRC channel 中的好心人,他们花一些时间为我指明了正确的方向。

关于nginx - php-fpm下获取Nginx调用PHP文件处理404错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13162998/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com