haproxy 504超时到apache

haproxy 504 timeout to apache

除了我们遇到的 504 问题之外,对 haproxy 还很陌生并且很喜欢它。相关日志输出为:

Jun 21 13:52:06 localhost haproxy[1431]: 192.168.0.2:51435 [21/Jun/2017:13:50:26.740] www-https~ beFootprints/foorprints 0/0/2/-1/100003 504 195 - - sH-- 2/2/0/0/0 0/0 "POST /MRcgi/MRlogin.pl HTTP/1.1"
Jun 21 13:54:26 localhost haproxy[1431]: 192.168.0.2:51447 [21/Jun/2017:13:52:46.577] www-https~ beFootprints/foorprints 0/0/3/-1/100005 504 195 - - sH-- 2/2/0/0/0 0/0 "POST /MRcgi/MRlogin.pl HTTP/1.1"
Jun 21 14:15:57 localhost haproxy[1431]: 192.168.0.1:50225 [21/Jun/2017:14:14:17.771] www-https~ beFootprints/foorprints 0/0/2/-1/100004 504 195 - - sH-- 3/3/0/0/0 0/0 "POST /MRcgi/MRlogin.pl HTTP/1.1"
Jun 21 14:22:26 localhost haproxy[1431]: 192.168.0.1:50258 [21/Jun/2017:14:20:46.608] www-https~ beFootprints/foorprints 0/0/2/-1/100003 504 195 - - sH-- 2/2/0/0/0 0/0 "POST /MRcgi/MRlogin.pl HTTP/1.1" 

在 haproxy.cfg

中使用以下超时值
defaults
        log     global
        mode    http
        option forwardfor
        option  httplog
        option  dontlognull
        timeout connect 5000
        timeout client  50000
        timeout server  100000

运行 Ubuntu 16.04.2 LTS

非常感谢任何帮助和评论!

问题似乎出在网络服务器上。检查那里的日志,您应该找到长 运行 请求。

这是我的结论。

在您的日志中注明 sH--。这就是session state at disconnection。这对于故障排除非常有价值。这些值是位置和区分大小写的。

s: the server-side timeout expired while waiting for the server to send or receive data.

...所以,timeout server 被解雇了,而...

H: the proxy was waiting for complete, valid response HEADERS from the server (HTTP only).

服务器还没有完成(也许甚至还没有开始)将所有响应头返回给代理,但是连接已经建立并且请求已经发送。

HAProxy returns 504 Gateway Timeout,说明后台没有及时响应

如果您的后端需要超过 100 秒 (?!),那么您需要增加 timeout server。否则,您的 Apache 服务器似乎有响应太慢的问题。

我遇到了类似的问题,发现问题出在我配置后端服务器部分的方式上。

backend no_match_backend
  mode http
  balance roundrobin
  option forwardfor
  option httpchk HEAD / HTTP/1.1\r\nHost:\ example.com
  server nginx-example 192.168.0.10 check port 80

我的问题是我没有指定连接端口。 当通过 HTTP 连接时它会工作,但因为我的 SSL 在我的 haproxy 上终止了。 这会尝试通过 443 连接到后端。 由于后端不能/不能正确通信。使用 haproxy 和导致网关超时的后端设置 SSL 会话。 我需要强制与后端进行未加密的通信。

backend no_match_backend
  mode http
  balance roundrobin
  option forwardfor
  option httpchk HEAD / HTTP/1.1\r\nHost:\ example.com
  server nginx-example 192.168.0.10:80 check port 80

更改可能很难发现 server nginx-example 192.168.0.10 check port 80 现在在 ip 192.168.0.10:80

之后有 :80

我的后端服务器配置了 SSL 重定向,这个问题变得更加复杂。所以我所有的请求都将以 HTTP 形式到达并被重定向到 HTTPS。所以很难确定问题出在哪里。我 看起来 https 请求已正确重定向到后端服务器。我需要在后端服务器上禁用此重定向并将其移至 haproxy config