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{
				312px;
				height:250px;
				border:3px solid #959595;
				border-radius: 8px;
				/*margin:0 auto;*/
				
			}
			.content header{
				 312px;
				height:37px;
				border-bottom: 2px solid #959595;
			}
			.content header i{
				display: block;
				15px;
				height:15px;
				border-radius: 50%;
				background-color:#959595 ;
				float:left;
				margin:10px 9px;
			}
			.content header i.white{
				10px;
				height:10px;
				border:3px solid #959595;				
				background-color: #fff;
			}
			.content header em{
				float:right;
				display: block;
				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{
				312px;
				height:250px;
				border:3px solid #959595;
				border-radius: 8px;
				/*margin:0 auto;*/
				
			}
			.content header{
				 312px;
				height:37px;
				border-bottom: 2px solid #959595;
			}
			.content header i{
				display: block;
				15px;
				height:15px;
				border-radius: 50%;
				background-color:#959595 ;
				float:left;
				margin:10px 9px;
			}
			.content header i.white{
				10px;
				height:10px;
				border:3px solid #959595;				
				background-color: #fff;
			}
			.content header em{
				float:right;
				display: block;
				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