
我向 haproxy 發出相同的請求(POST /user/oauth),但有時我收到 503,直接向後端發送請求總是有效
這是日誌:
- local_server~ app/s2 0/0/0/100/100 200 813 - - --VN 1/1/0/0/0 0/0 "POST /user/oauth HTTP/1.1"
- local_server~ app/s1 0/0/1/107/108 200 820 - - --NI 1/1/0/0/0 0/0 "POST /user/oauth HTTP/1.1"
- local_server~ app/NOSRV 0/-1/-1/-1/0 503 216 - - SCNN 1/1/0/0/0 0/0 “POST /user/oauth HTTP/1.1”
- local_server~ app/NOSRV 0/-1/-1/-1/0 503 216 - - SCNN 1/1/0/0/0 0/0 “POST /user/oauth HTTP/1.1”
- local_server~ app/s2 0/0/1/106/107 200 831 - - --NI 2/2/0/0/0 0/0 “POST /user/oauth HTTP/1.1”
- local_server~ app/s1 0/0/1/3/6206 101 337 - - --NI 3/3/1/1/0 0/0“GET / HTTP/1.1”
- local_server~ app/s1 0/0/1/83/84 200 258 - - --VN 2/2/0/0/0 0/0 “POST /transaction/conclusionTransaction HTTP/1.1”
- local_server~ app/NOSRV 0/-1/-1/-1/0 503 216 - - SCNN 1/1/0/0/0 0/0 “POST /user/oauth HTTP/1.1”
- local_server~ app/s2 0/0/1/107/108 200 831 - - --NI 1/1/0/0/0 0/0 "POST /user/oauth HTTP/1.1"
如您所看到的,POST /user/oauth 有時會轉到 s1,有時會轉到 s2,有時會轉到 NOSRV。
有時連續10次通過,有時連續10次失敗。
這是我的配置:
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 10000
timeout client 50000
timeout server 50000
retries 3
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
frontend local_server
bind *:8080 ssl crt /etc/letsencrypt/live/xxx/sslcert.pem
mode http
default_backend app
backend app
balance roundrobin
cookie SERVERID insert indirect nocache
http-send-name-header Host
server s1 172.26.13.134:3000 check cookie s1
server s2 172.26.13.134:3000 check cookie s2
http-request add-header X-Server %b
編輯:
我確實將請求重定向到在本地主機上運行的快速 python 伺服器,但問題仍然存在。所以我編輯了 haproxy 設定文件,只讓伺服器 s1 127.0.0.1:8086 檢查 cookie s1
並執行 python 腳本: python3 -m http.server 8086 --bind 127.0.0.1&
當我從郵差打來的時候,我連續得到了 3 個 succ,而不是 503。
答案1
我相信問題出在版本內,我在某處讀到版本 1.9 比 2.* 我下載了源代碼並使用以下選項進行編譯 make TARGET=linux-glibc USE_PCRE2=1 USE_PCRE2_JIT=1 USE_OPENSSL=1 USE_ZLIB=1 USE_REGPA =1 USE_SYSTEMD=1 USE_THREAD=1
正如你所看到的,我故意省略了 lua5 選項,這是與你從 apt-get install 獲得的選項的唯一區別。
結果 binay 工作得很好,沒有任何問題