我正在使用503 HTTP状态,即将进入维护模式页面。
有没有办法让HAproxy服务器端生成的503页面,而不是默认的空白/不可用页面?
我正在使用Openshift + HAproxy + Cloudflare + PHP。
提前致谢。
Haproxyconfiguration(一些评论删除):
#--------------------------------------------------------------------- # Global settings #--------------------------------------------------------------------- global log 127.0.0.1 local2 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 4000 user haproxy group haproxy daemon # turn on stats unix socket stats socket /var/lib/haproxy/stats #--------------------------------------------------------------------- # common defaults that all the 'listen' and 'backend' sections will # use if not designated in their block #--------------------------------------------------------------------- defaults mode http log global option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 option redispatch retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s maxconn 3000 #--------------------------------------------------------------------- # main frontend which proxys to the backends #--------------------------------------------------------------------- frontend main *:5000 acl url_static path_beg -i /static /images /javascript /stylesheets acl url_static path_end -i .jpg .gif .png .css .js use_backend static if url_static default_backend app #--------------------------------------------------------------------- # static backend for serving up images, stylesheets and such #--------------------------------------------------------------------- backend static balance roundrobin server static 127.0.0.1:4331 check #--------------------------------------------------------------------- # round robin balancing between the various backends #--------------------------------------------------------------------- backend app balance roundrobin server app1 127.0.0.1:5001 check server app2 127.0.0.1:5002 check server app3 127.0.0.1:5003 check server app4 127.0.0.1:5004 check
是。 使用错误文件指令,例如通过:
errorfile 503 /etc/haproxy/errors/503.http
语法如下:
errorfile <code> <file>
引用文档:
<code> is the HTTP status code. Currently, HAProxy is capable of generating codes 200, 400, 403, 405, 408, 429, 500, 502, 503, and 504. <file> designates a file containing the full HTTP response. It is recommended to follow the common practice of appending ".http" to the filename so that people do not confuse the response with HTML error pages, and to use absolute paths, since files are read before any chroot is performed.
例如,文件的内容可以是:
HTTP/1.1 503 Service Unavailable\r\n Cache-Control: no-cache\r\n Connection: close\r\n Content-Type: text/html\r\n <html> <head> <title>Service unavailable</title> </head> <body> <h1>Service unavailable</h1> </body>
有没有办法让HAproxy服务器端生成的503页面,而不是默认的空白/不可用页面?
这不是你应该问的实际问题。 HAProxy总是使用服务器的响应。 错误文件仅用于由HAProxy 内部生成的错误。
如果您检查您的Web服务器日志,您会发现这些特定的请求实际上并未发送到Web服务器。
发生这种情况是因为HAProxy认为你的服务器closures了,因为它正在从服务器获取503以响应健康检查。
如果服务器正在返回502或400或健康状况检查中的任何错误代码,则仍会从HAProxg收到503,因为服务器正式停止运行。
WARNING] 201/142518 (192371) : Server express/local-gear is DOWN, reason: Layer7 wrong status, code: 503, info: "HTTP status check returned code <3C>503<3E>", check duration: 87ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue
你显然option httpchk从你发布的configuration中option httpchk了行option httpchk ,但它必须在那里,否则HAProxy只会执行第4层检查,而这不会发生。
最简单的解决scheme是从后端或默认configuration中删除该行。