Nginx 自定义404、500、502 页面
利用nginx的反向代理来实现 服务器404 和500 等状态码的自定义页面
1.nginx配置文件 nginx.conf 配置开启代理错误拦截 和配置页面 下划线部分
http {
......
proxy_intercept_errors on;
fastcgi_intercept_errors on;
server {
......
error_page 404 /notfind.html;
error_page 500 /error.html;
error_page 502 503 504 /error502.html;
}
}
2.编写自定义页面,将页面放置在nginx路径下的html 文件夹下 页面中用到的图片什么的都放置与此文件夹下

3.重启nginx 配置生效 OK
404页面代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" type="image/x-icon" href="http://zhaixt.info/icon.ico" />
<title>404-对不起!您访问的页面不存在</title>
<style type="text/css">
.head404{ width:580px; height:234px; margin:50px auto 0 auto; background:url(http://zhaixt.info/head404.png) no-repeat; }
.txtbg404{ width:499px; height:169px; margin:10px auto 0 auto; background:url(http://zhaixt.info/txtbg404.png) no-repeat;}
.txtbg404 .txtbox{ width:390px; position:relative; top:30px; left:60px;color:#eee; font-size:13px;}
.txtbg404 .txtbox p {margin:5px 0; line-height:18px;}
.txtbg404 .txtbox .paddingbox { padding-top:15px;}
.txtbg404 .txtbox p a { color:#eee; text-decoration:none;}
.txtbg404 .txtbox p a:hover { color:#FC9D1D; text-decoration:underline;}
</style>
</head>
<body bgcolor="#494949">
<div class="head404"></div>
<div class="txtbg404">
<div class="txtbox">
<p>对不起,您请求的页面不存在、或已被删除、或暂时不可用</p>
<p class="paddingbox">请点击以下链接继续浏览网页</p>
<p>》<a style="cursor:pointer" onclick="history.back()">返回上一页面</a></p>
<p>》<a href="http://zhaixt.info/screenShot/index"> 文字识别 </a></p>
<p>》<a href="http://zhaixt.info/excelchange/index"> 图表转换 </a></p>
</div>
</div>
</body>
</html>
500页面代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>We're sorry, but something went wrong (500)</title>
<meta charset="UTF-8" http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" type="image/x-icon" href="http://zhaixt.info/icon.ico" />
<style type="text/css"> .head500{ width:580px; height:234px; margin:50px auto 0 auto; background:url(http://zhaixt.info/head500.png) no-repeat; } .txtbg500{ width:499px; height:169px; margin:10px auto 0 auto; background:url(http://zhaixt.info/txtbg404.png) no-repeat;} .txtbg500 .txtbox{ width:390px; position:relative; top:30px; left:60px;color:#eee; font-size:13px;} .txtbg500 .txtbox p {margin:5px 0; line-height:18px;} .txtbg500 .txtbox .paddingbox { padding-top:15px;} .txtbg500 .txtbox p a { color:#eee; text-decoration:none;} .txtbg500 .txtbox p a:hover { color:#FC9D1D; text-decoration:underline;} </style>
</head> <body bgcolor="#494949"> <div class="head500"></div> <div class="txtbg500"> <div class="txtbox"> <p class="paddingbox">请点击以下链接继续浏览网页</p> <p>》<a style="cursor:pointer" onclick="history.back()">返回上一页面</a></p> <p>》<a href="http://zhaixt.info/screenShot/index"> 文字识别 </a></p> <p>》<a href="http://zhaixt.info/excelchange/index"> 图表转换 </a></p> </div> </div> </body>
</html>
502页面代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>We're sorry, but something went wrong (502)</title>
<meta charset="UTF-8" http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" type="image/x-icon" href="http://zhaixt.info/icon.ico" />
<style type="text/css"> .head500{ width:580px; height:234px; margin:50px auto 0 auto; background:url(http://zhaixt.info/502.png) no-repeat; } .txtbg500{ width:499px; height:169px; margin:10px auto 0 auto; background:url(http://zhaixt.info/txtbg404.png) no-repeat;} .txtbg500 .txtbox{ width:390px; position:relative; top:30px; left:60px;color:#eee; font-size:13px;} .txtbg500 .txtbox p {margin:5px 0; line-height:18px;} .txtbg500 .txtbox .paddingbox { padding-top:15px;} .txtbg500 .txtbox h1,h2{ color:#FC9D1D;} </style>
</head> <body bgcolor="#494949"> <div class="head500"></div> <div class="txtbg500"> <div class="txtbox"> <h1> SORRY </h1> <h2>服务升级中...如等待时间过长,请联系宅小涛</h2> </div> </div> </body>
</html>
欢迎大家参考 !



Nginx 自定义404、500、502 页面的更多相关文章
- nginx自定义404、403页面
1.在nginx的http模块加入: fastcgi_intercept_errors on; 2.在server模块加入 location / { root /data; index index.h ...
- apache 网页301重定向、自定义400/403/404/500错误页面
首先简单介绍一下,.htaccess文件是Apache服务器中的一个配置文件(Nginx服务器没有),它负责相关目录下的网页配置.通过对.htaccess文件进行设置,可以帮我们实现:网页301重定向 ...
- Nginx 自定义404、500错误页面跳转
自定义Nginx错误界面跳转 1.开启Nginx.conf配置文件下的自定义接口参数. http { fastcgi_intercept_errors on; } 2.在Server区域添加自定义的错 ...
- Nginx自定义404页面并返回404状态码
Nginx定义404页面并返回404状态码, WebServer是nginx,直接告诉我应该他们配置了nginx的404错误页面,虽然请求不存在的资源可以成功返回404页面,但返回状态码确是200. ...
- .net core 自定义404 500页面
常用处理方式 自己定制网站的404.500页面的方式有很多,比如修改nginx配置文件,指定请求返回码对应的页面, .netframework项目中修改webconfig文件,指定customerro ...
- Nginx自定义404页面
指定一个错误页面: error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } 指定一个url地址: ...
- asp.net mvc输出自定义404等错误页面,非302跳转。
朋友问到一个问题,如何输出自定义错误页面,不使用302跳转.当前页面地址不能改变. 还要执行一些代码等,生成一些错误信息,方便用户提交反馈. 500错误,mvc框架已经有现成解决方法: filters ...
- asp.net mvc输出自定义404等错误页面,非302跳转
朋友问到一个问题,如何输出自定义错误页面,不使用302跳转.当前页面地址不能改变. 还要执行一些代码等,生成一些错误信息,方便用户提交反馈. 500错误,mvc框架已经有现成解决方法: filte ...
- http协议的状态码——400,401,403,404,500,502,503,301,302等常见网页错误代码
http协议的状态码 1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态码. 100(继续) 请求者应当继续提出请求.服务器返回此代码表示已收到请求的第一部分,正在等待其余部分. 101( ...
随机推荐
- [物理学与PDEs]第2章第2节 粘性流体力学方程组 2.1 引言
1. 实际的流体与理想流体的主要区别在于: 前者具有粘性 (内摩擦) 和热传导. 2. 内摩擦 (1) 当两层流体有相对运动时, 方有摩擦力; 它是一种内力; 单位面积上所受的内力称为应力; 而 ...
- SQL注入绕过技巧总结
1.SQL注入过程中的处理# 终端payload编码------>web服务器解码-------->CGI脚本解码------>web应用解码----->数据库解码 浏览器.代 ...
- Mongodb注入
0x01 Brief Description 作为nosql(not only sql)数据库的一种,mongodb很强大,很多企业也在用到.相对于sql数据库,nosql数据库有以下优点:简单便捷. ...
- frame的用法
<iframe> 标签规定一个内联框架.一个内联框架被用来在当前 HTML 文档中嵌入另一个文档. 所有的主流浏览器都支持<iframe>标签.你可以把提示的文字放到 < ...
- C#利用VUDP.cs开发网络通讯应用例程
VClassLib-CS项目Github地址:https://github.com/velscode/VClassLib-CS VUDP文档地址:https://github.com/velscode ...
- python 中and,or计算规则
and :如果表达式都不为假,则返回最后一个表达式的值,如果为假返回第一个表达式为假的值.(遇到假的表达式就返回此表达式的值) or :如果都为假,,返回最后一个假表达式的值,如果有真,则返回第一个真 ...
- Django Tastypie: 贴士,技巧和故障排除
为Resource加入字段 1.为字段实现专门的dehydrate函数 2.实现(resource级别的)dehydrate方法 3.额外的方法 排除故障 通过外键,外键的反向关系来映射一个对象的属性 ...
- LNMP下安装Pureftpd开启FTP服务以及修改FTP端口的方法
LNMP 环境包 1.2 内置了 Pureftpd 的安装程序. 安装 Pureftpd 进入lnmp解压后的目录,执行:./pureftpd.sh 会显示如下图: 按提示输入当前MySQL的root ...
- Axis接口
Axis支持三种web service的部署和开发,分别为: 1.Dynamic Invocation Interface ( DII) 2.Dynamic Proxy方式 3.Stubs方式Dyna ...
- 微信H5支付坑一--手续费未结算
简单随笔小记: 场景:在微信H5支付的过程中,无论怎么支付完成,在微信商户后台查询手续费依然未扣除,当时手续费账户月为5元. 解决方法:起初无论怎么测试都不知道代码到底问题出在哪里了,想一下手续费账户 ...