haproxy实现自定义错误页面的内容
2024-10-16 05:38:40
现在利用haproxy实现自定义的haproxy的错误页面
我们现在实现自定义错误页面有以下的方法;
一种是自定义错误页面
haproxy.conf
defaults
errorfile 404 /etc/haproxy/errors/404.http
errorfile 503 /etc/haproxy/errors/503.http
还有一种方法就是错误页面的跳转:
当出现错误的时候,我们跳转到指定的链接地址
frontend web_server
bind *:80
default_backend webserver
acl badguy src 10.0.10.1
block if badguy
errorloc 403 http://baidu.com/ 这样出错的时候直接跳转到指定的URL地址。即百度页面
记录一下我这里的实现过程
应同事需求,让前端用js写了一个页面,然后放在503页面上
503.html文件内容是:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>503</title>
<style>
*{
margin:0;
padding:0;
}
.article{
position:absolute;
top:50%;
left:50%;
transform: translate(-50%,-50%);
}
.content{
width:312px;
height:250px;
border:3px solid #959595;
border-radius: 8px;
/*margin:0 auto;*/ }
.content header{
width: 312px;
height:37px;
border-bottom: 2px solid #959595;
}
.content header i{
display: block;
width:15px;
height:15px;
border-radius: 50%;
background-color:#959595 ;
float:left;
margin:10px 9px;
}
.content header i.white{
width:10px;
height:10px;
border:3px solid #959595;
background-color: #fff;
}
.content header em{
float:right;
display: block;
width:16px;
height:16px;
border:3px solid #959595;
border-radius: 50%;
margin:7px 17px;
font-style: normal;
font:22px/13px "微软雅黑";
color:#959595;
}
.content .main h1 {
height:206px;
font:bold 100px/206px "微软雅黑";
color:#959595;
text-align: center;
}
h2{
font:30px/110px "微软雅黑";
color:#666666;
margin-left: -14px;
} </style>
</head>
<body>
<div class="article">
<div class="content">
<header>
<div class="left">
<i></i>
<i></i>
<i class="white"></i>
</div>
<div class="right">
<em>×</em>
</div>
</header>
<div class="main">
<h1>503</h1>
</div>
</div> </div>
</body>
</html>
但是我们要用在haproxy的话,我们需要在文件头添加如下几行内容(注意了,两个之间需要有一个空行,一定不能忘了):
HTTP/1.0 503 Service Unavailable
Cache-Control: no-cache
Connection: close
Content-Type: text/html
拼接后的文件内容为503.http(把503.html修改成503.http)
HTTP/1.0 503 Service Unavailable
Cache-Control: no-cache
Connection: close
Content-Type: text/html <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>503</title>
<style>
*{
margin:0;
padding:0;
}
.article{
position:absolute;
top:50%;
left:50%;
transform: translate(-50%,-50%);
}
.content{
width:312px;
height:250px;
border:3px solid #959595;
border-radius: 8px;
/*margin:0 auto;*/ }
.content header{
width: 312px;
height:37px;
border-bottom: 2px solid #959595;
}
.content header i{
display: block;
width:15px;
height:15px;
border-radius: 50%;
background-color:#959595 ;
float:left;
margin:10px 9px;
}
.content header i.white{
width:10px;
height:10px;
border:3px solid #959595;
background-color: #fff;
}
.content header em{
float:right;
display: block;
width:16px;
height:16px;
border:3px solid #959595;
border-radius: 50%;
margin:7px 17px;
font-style: normal;
font:22px/13px "微软雅黑";
color:#959595;
}
.content .main h1 {
height:206px;
font:bold 100px/206px "微软雅黑";
color:#959595;
text-align: center;
}
h2{
font:30px/110px "微软雅黑";
color:#666666;
margin-left: -14px;
} </style>
</head>
<body>
<div class="article">
<div class="content">
<header>
<div class="left">
<i></i>
<i></i>
<i class="white"></i>
</div>
<div class="right">
<em>×</em>
</div>
</header>
<div class="main">
<h1>503</h1>
</div>
</div> </div>
</body>
</html>
最后修改一下haprox.cfg的配置文件
errorfile 503 /etc/haproxy/errfile/503.http
重启一下haproxy。完成
参考文件:
http://blief.blog.51cto.com/6170059/1752669
http://qiita.com/myaaaaa_chan/items/23de67f76a70030ccde9
最新文章
- C# Socket简单例子(服务器与客户端通信)
- JS网页顶部弹出可关闭广告图层
- ServletContext与网站计数器
- 用c语言编写二分查找法
- Percona XtraDB Cluster(转)
- 洛谷P1206 [USACO1.2]回文平方数 Palindromic Squares
- unity调用MMBilling_2.4.2 Android SDK.
- 动软代码生成器三层用于winform
- Cogs 12 运输问题2 (有上下界网络流)
- Navicat_Preminum
- ARP 和 RARP
- AspNetCore-MVC实战系列(四)之结尾
- Pycharm节能模式
- 给ASP.NET Core Web发布包做减法
- BLEU (Bilingual Evaluation Understudy)
- jquery中的全选、反选、全不选和单删、批删
- 总结:基于Oracle Logminer数据同步
- 如何使用 Visual C# 2005 或 Visual C# .NET 向 Excel 工作簿传输数据
- CentOS7 - 给VMwear Workstation 15安装VMwear tools
- Codeforces Round #275 (Div. 2) A,B,C,D
热门文章
- Windows系统变量
- Android-socket服务端断重启后,android客户端自动重连
- Android Activity launchMode研究
- [Objective-C]关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)
- android四大组件(简单总结)
- (四)新建Maven项目
- [Erlang 0104] 当Erlang遇到Solr
- params可变参数
- postgres扩展开发
- Webservice详解