2016-03-02 322 views
1

我們使用Tomcat 8和HAProxy 1.5.4。我們從Haproxy中隨機獲得502個錯誤的網關錯誤。當我們直接訪問Tomcat時,錯誤不會顯示,所以它必須與Haproxy如何配置有關。Haproxy&Tomcat隨機結果502 Bad Gateway

任何指針將非常感激!請在下面找到錯誤和配置文件。謝謝!

錯誤日誌:

3月1日11時41分37秒WWW1 HAProxy的[15362]:XX.XX.XX.XX:56387 [01/MAR/2016:11:41:35.480] https-in_server/www1a 1987/0/0/-1/2029 502 8878 - - PH_1764/1758/46/26/0 0/0「POST /abc/test/b25766378a05446496645649e2ddaf7a/poll 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 
+0

我建議爲後端服務器使用私有IP地址10.x.x地址。 –

回答

0

我曾與Tomcat和HAProxy的同樣的問題。 Tomcat的是在迴應一個HTTP 200響應,但被的haproxy它進行代理,並用502 響應的原因是在於HAProxy的限制:

tune.bufsize 1638400 tune.http.maxhdr 10000

我改變這種兩屬性的價值很高。默認值是限制性的,並將來自後端的http 200響應轉換爲502響應。 請注意這兩個屬性的高值,因爲您可能很容易產生內存問題。 一旦我改變了這個屬性,502的問題就結束了。

相關問題