我们使用的是带有HAProxy 1.5.4的Tomcat 8。我们从HAProxy中随机收到502 Bad Gateway错误。当我们直接访问Tomcat时,错误没有出现,所以一定是HAProxy的配置方式有问题。
任何指针将非常感谢!请在下面找到错误和配置文件。谢谢!
错误日志:
3月1日11时41分37秒xx.xx. xx.xx.xx:56387 [2016年3月1日:11:41:35.480] https-in~服务器/www 1a 1987/0/0/-1/2029 502 8878 - - PH-- 1764/1758/46/26/0 0/0“开机自检/abc/测试/b25766378 a05446496645649 e2 ddaf 7a/轮询HTTP/1.1”
Tomcat HTTP连接器配置
<Connector
URIEncoding = "UTF-8"
port = "8080"
protocol = "HTTP/1.1"
maxThreads = "1850"
connectionTimeout = "900000"
keepAliveTimeout = "900000"
maxKeepAliveRequests = "-1"/>
Haproxy配置
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 777 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
# Per process limit: The default is 2000, too small for us
maxconn 18000
# Increase the cache from 20000 (default), higher values reduce CPU usage
tune.ssl.cachesize 60000
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL).
ssl-default-bind-ciphers kEECDH+aRSA+AES:kRSA+AES:+AES256:!kEDH:!LOW:!EXP:!MD5:!aNULL:!eNULL
ssl-default-bind-options no-sslv3 no-tls-tickets
defaults
log global
mode http
option httplog
option http-server-close
option forwardfor
option dontlognull
# Set the listen limit: The default is 2000, too small for us
maxconn 9000
# we should fix this
option accept-invalid-http-response
option accept-invalid-http-request
no option checkcache
timeout connect 80000
timeout client 900000
timeout server 500000
frontend http-in
bind *:80
# Redirect all subdomains to www.
redirect prefix https://www.example.com code 301 if !{ hdr_beg(host) -i www. }
# Redirect all trafic to https
redirect scheme https if !skip_pages !{ ssl_fc }
default_backend servers
frontend https-in
# add no-tlsv10 for disabling tls 1.0
bind *:443 ssl crt /etc/ssl/private/www_example_com.pem
default_backend servers
# Redirect all subdomains to www.
redirect prefix https://www.example.com code 301 if !{ hdr_beg(host) -i www. }
backend servers
# Every connection is closed and opened to the server
option http-server-close
# Recommended to enable
option http-pretend-keepalive
# The url to check the backend servers health
option httpchk GET /srvstatus.htm
# Balancing
balance roundrobin
appsession JSESSIONID len 52 timeout 3h request-learn prefix
stick-table type string len 32 size 1M expire 3h
# We have 3 backend servers, one is for backup
server www1a 127.0.0.1:8080 check
server www2a xx.xx.xx.xx:8080 check
server www1b 127.0.0.1:8081 check backup
2条答案
按热度按时间rta7y2nd1#
我在使用Tomcat和haproxy时遇到了同样的问题,Tomcat响应的是http 200响应,而haproxy代理了它,并以502响应,原因在于haproxy的限制:
我将这两个属性更改为高值。默认值是限制性的,并将HTTP 200响应从后端转换为502响应。请小心这两个属性的高值,因为您很容易出现内存问题。一旦我更改了此属性,502的问题就解决了。
8wigbo562#
不幸的是Robertos的回答并没有帮助我,但阅读我的haproxy日志,他们非常积极地要求你设置超时,所以在我绝望的时候,我这样做了:
现在,后面有tomcat的haproxy不再返回任何502。
我不明白为什么,因为默认值似乎是3秒,而我的延迟是〈50毫秒。