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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值