MySQL, Oracle, Linux, 软件架构及大数据技术知识分享平台

网站首页 > 精选文章 / 正文

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

2025-06-15 16:35 huorong 精选文章 3 ℃ 0 评论

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

Tags:nginx指定配置文件重启

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言