一分钟学会:Nginx开启自定义错误页面
在网上搜索404配置,有很多配置文章,但都是关于fastcgi_intercept_errors的,不过对我们的项目不起作用。我们的项目使用nginx做反向代理,通过域名区分不同的网站,配置fastcgi_intercept_errors不生效,需要配置proxy_intercept_errors。
在我们服务器重启或者报错的时候,为了不让用户访问报错,可以自定义错误页面,配置方式如下:
1、在http{}中假如如下代码
#开启自定义错误页面
proxy_intercept_errors on;
#下面的配置不生效
#fastcgi_intercept_errors on;
2、在server中假如如下代码
error_page 404 /404.html;
location = /404.html {
root /data/fileupload;
}
error_page 500 502 503 504 /error.html;
location = /error.html {
root /data/fileupload;
}
上面的两个静态文件404.html和error.html是我们要跳转的错误页面,放在我的服务器的/data/fileupload下,访问不存在的页面,效果如下:

相关推荐
-
PHP8种变量类型的详细讲解2025-02-22 00:32:24
-
php+apache 和 php+nginx的区别2025-02-22 00:21:27
-
PHP:与workerman结合实现定时任务2025-02-22 00:15:57
-
Nginx的Rewrite规则与实例2025-02-22 00:15:39
-
MySql中身份证字段的简单脱敏介绍2025-02-22 00:15:36