对指定的报错进行重定向,进行优雅的显示错误页面,使用errorfile和errorloc指令的两种方法,可以实现自定义各种错误页面。
haproxy默认使用的错误页面:
一、基于自定义的错误页面
自定义错误页 :errorfile <code> <file>
<code>:HTTP status ,支持200, 400, 403, 405, 408, 425, 429, 500, 502,503,504
<file>:包含完整HTTP响应头的错误页文件的绝对路径。 建议后缀".http",以和一般的html文件相区分
1、编辑haproxy.cfg配置文件
vim /etc/haproxy/haproxy.cfg
重启服务:
systemctl restart haproxy.service
2、创建自定义错误页面,并编辑
[root@haproxy ~]# mkdir /haproxy/errorpages/ -p
[root@haproxy ~]# cp /usr/share/haproxy/503.http /haproxy/errorpages/503page.http
[root@haproxy ~]# vim /haproxy/errorpages/503page.http
关闭后端的RS主机,进行测试
二、基于http重定向错误页面
错误页面重定向:errorloc <code> <url>
相当于errorloc302 <code> <url> ,利用302重定向至指URL
1、编辑haproxy.cfg配置文件
vim /etc/haproxy/haproxy.cfg
重启服务:
systemctl restart haproxy.service
2、测试
浏览器访问172.25.254.100,自动跳转到百度