haproxy实现自定义错误页面的内容
现在利用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
haproxy实现自定义错误页面的内容的更多相关文章
- ASP.NET Core中显示自定义错误页面
在 ASP.NET Core 中,默认情况下当发生500或404错误时,只返回http状态码,不返回任何内容,页面一片空白. 如果在 Startup.cs 的 Configure() 中加上 app. ...
- ASP.NET全局错误处理和异常日志记录以及IIS配置自定义错误页面
应用场景和使用目的 很多时候,我们在访问页面的时候,由于程序异常.系统崩溃会导致出现黄页.在通常的情况下,黄页对于我们来说,帮助是极大的,因为它可以帮助我们知道问题根源,甚至是哪一行代码出现了错误.但 ...
- Spring Boot自定义错误页面,Whitelabel Error Page处理方式
我已经是Spring Framework框架的忠实粉丝.对于企业软件开发者来说它提供了对常见问题的通用解决方案,包括那些你在未来开发中没有意识到的问题.但是,它构建的J2EE项目变得比较臃肿,需要被一 ...
- ASP.NET自定义错误页面
ASP.NET自定义错误页面 ASP.NET 提供三种用于在出现错误时捕获和响应错误的主要方法:Page_Error 事件.Application_Error 事件以及应用程序配置文件 (Web.co ...
- ASP.NET网站中设置404自定义错误页面
在用ASP.NET WebForm开发一个网站时,需要自定义404错误页面. 做法是这样的 在网站根目录下建立了一个404.html的错误页面,然后在Global.asax文件中,加入如下代码: &l ...
- .net自定义错误页面实现升级篇
问题描述: 在上一篇博文 ".net自定义错误页面实现" 中已经介绍了在.net中如何实现自定义错误页面实现(有需要者可以去上一篇博文了解),单纯按照上一篇博文那样设置,能够实现所 ...
- (后端)Spring Boot自定义错误页面,Whitelabel Error Page处理方式(转)
我已经是Spring Framework框架的忠实粉丝.对于企业软件开发者来说它提供了对常见问题的通用解决方案,包括那些你在未来开发中没有意识到的问题.但是,它构建的J2EE项目变得比较臃肿,需要被一 ...
- flask模板应用-自定义错误页面
自定义错误页面 当程序返回错误响应时,会渲染一个默认的错误页面,我们可以注册错误处理函数来处理错误页面 错误处理函数和视图函数很相似,返回值将作为响应的主题,因此我们先要创建错误页面的模板文件.为了和 ...
- Springboot - 自定义错误页面
Springboot 没找到页面或内部错误时,会访问默认错误页面.这节我们来自定义错误页面. 自定义错误页面 1.在resources 目录下面再建一个 resources 文件夹,里面建一个 err ...
随机推荐
- [SharePoint]javascript client object model 获取lookup 类型的field的值,包括user类型(单人或者多人)的值。how to get the multiple user type/lookup type field value by Javascript client object model
1. how to get value var context = new SP.ClientContext.get_current(); var web = context.get_web(); v ...
- MyEclipse 2016 CI 4新增BootStrap模板
Live Preview with CodeLive 目前CodeLive还只有Live Preview这一个功能,在后续的版本中会陆续添加新功能. 新增Bootstrap模板 在模板面板中选择相应的 ...
- SharePoint Permission Extension
SharePoint Permission Extension 项目很久没维护了,也没有迁移到sp2013上(貌似只要把2013的Form的RenderMode设置为Server后也是可以用的). 在 ...
- Android Studio导入修改
- Golang(笔记) 顺序编程
package main import ( "fmt" "bufio" "io" "os" "strconv& ...
- 浅谈html5 响应式布局
一.什么是响应式布局? 响应式布局是Ethan Marcotte在2010年5月份提出的一个概念,简而言之,就是一个网站能够兼容多个终端——而不是为每个终端做一个特定的版本. 这个概念是为解决移动互联 ...
- IOS开发基础知识--碎片44
1:App跳转至系统Settings 跳转在IOS8以上跟以下是有区别的,如果是IOS8以上可以如下设置: NSURL *url = [NSURL URLWithString:UIApplicatio ...
- iframe大小自适应
前几天,舍友去某互联网公司面前端研发工程师.回来后,他就跟我们聊了下面试官给他出的题.其中,有一道题是“如何实现iframe高度的自适应?”.好吧,我承认,我听到iframe这个词的第一反应就是:这个 ...
- [css]我要用css画幅画(三)
接着之前的[css]我要用css画幅画(二), 今天,我画了一个小人,他的名字暂时叫作小明. 以下只列出本次修改增加的内容 html如下: <div class="human left ...
- CSS补充与JavaScript基础
一.CSS补充 position 1.fiexd 固定在页面的某个位置; 示例将顶部菜单始终固定在页面顶部 position: fixed; 将标签固定在某个位置 right: 0; 距离右边0像素 ...