一分钟学会:Nginx开启自定义错误页面

一分钟学会:Nginx开启自定义错误页面

经验文章nimo972025-06-07 17:08:451A+A-

在网上搜索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下,访问不存在的页面,效果如下:

点击这里复制本文地址 以上内容由nimo97整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
qrcode

尼墨宝库 © All Rights Reserved.  蜀ICP备2024111239号-7