大网数据广告活动
服务器运维问答

HAProxy - putting up a maintenance page

· 52CE 我爱测

Is there an easy way to dissable All backends in haproxy, and instead serve an appropriate maintenance page (for http requests)? I've read a little about the dissabled option, which I understand is per-server, but am wondering if…

问题原文

原帖链接 · UpTheCreek · CC BY-SA 3.0

Is there an easy way to dissable All backends in haproxy, and instead serve an appropriate maintenance page (for http requests)?

I've read a little about the dissabled option, which I understand is per-server, but am wondering if there is a way to simply stop traffic to all backends?

社区高分解答

原帖链接 · daff · CC BY-SA 3.0

The backup keyword is what we use for this. See this example:

listen example_com 0.0.0.0:8001
...
option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www.example.com\r\nUser-Agent:\ HAProxy
server  web01 10.1.31.21:80 cookie cookie_web01 check inter 5000 rise 2 fall 5 disabled
server  web02 10.1.31.22:80 cookie cookie_web02 check inter 5000 rise 2 fall 5 disabled
server  prx   10.1.31.10:9000  backup

Here both servers web01 and web02 are set to disabled, in which case the backup server prx on 10.1.31.10:9000 will be used, which serves a maintenance page. The prx server in our case is the HAProxy server itself and on port 9000 runs an Apache HTTPD, serving the maintenance content:

<VirtualHost *:9000>
    ServerName  example.com
    ServerAdmin [email omitted]

    DocumentRoot /var/www/example.com/errors/
    <Directory /var/www/example.com/errors/>
        Options -Indexes
    </Directory>

    RewriteEngine On
    RewriteCond %{DOCUMENT_ROOT}/systemDown.html -f
    RewriteCond %{SCRIPT_FILENAME} !systemDown.html
    RewriteRule ^.*$ /systemDown.html [R=503,L]
    ErrorDocument 503 /systemDown.html

</VirtualHost>

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-03-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。