博主辛苦了,我要打赏银两给博主,犒劳犒劳站长。
【摘要】在网站程序中出现 404 问题是一个极为平常的现象,本文讲讲在 nginx 下,当访问 *.php 文件不存在时,如何设置自定义的 404 页面
假如不存在的文件后缀不以 .php 为结尾,则在 nginx 1.12.2 下,设置 error_page 参数,此参数位于 http 字段中的 server 字段内:
http{
server{
error_page 404 /404.html; # 显示根目录下的 404.html 文件,并不跳转
# error_page 404 http://www.baidu.com; # 当出现 404 时设置成自动跳转到百度首页
}
}
若缺失的文件是 php 文件(以 .php 为结尾),则需要开启 fastcgi_intercept_errors:
http{
fastcgi_intercept_errors on; # 默认配置文件是不存在这条配置的,需要手动添加
server{
error_page 404 /404.html; # 显示根目录下的 404.html 文件
}
}
当然最后需要重启 nginx:nginx -s reload
版权归 马富天个人博客 所有
本文标题:《nginx 下 php 文件不存在时,使用 fastcgi_intercept_errors 设置默认自定义 404 页面》
本文链接地址:http://www.mafutian.com/383.html
转载请务必注明出处,小生将不胜感激,谢谢! 喜欢本文或觉得本文对您有帮助,请分享给您的朋友 ^_^
顶0
踩0
评论审核未开启 |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
||