出于某種原因,haproxy 正在轉換我的請求。下面是日志輸出。
wc_haproxy | 172.29.0.1:35296 [03/Nov/2021:22:03:44.901] http http/<NOSRV> 0/-1/-1/-1/0 302 134 - - LR-- 1/1/0/0/0 0/0 "POST /register HTTP/1.1"
wc_haproxy | 172.29.0.1:58040 [03/Nov/2021:22:03:44.906] http~ app/app1 0/0/1/0/1 404 130 - - ---- 1/1/0/0/0 0/0 "GET /register HTTP/1.1"
下面是我的配置:
global
log stdout format raw local0
defaults
mode http
timeout client 10s
timeout connect 5s
timeout server 10s
timeout http-request 10s
log global
frontend http
bind *:80
bind *:443 ssl crt /usr/local/etc/haproxy/company.com.pem
redirect scheme https if !{ ssl_fc }
option httplog
acl sub1 hdr_sub(host) -i app.company.com
use_backend app if sub1
use_backend frontstore
backend frontstore
option forwardfor
option httpchk GET /
http-check send ver HTTP/1.1 hdr Host frontstore
server frontstore1 frontstore:8001 check
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
backend app
option forwardfor
option httpchk GET /check
http-check send ver HTTP/1.1 hdr Host app
server app1 app:8002 check
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
有誰知道為什么會這樣做?
僅供參考,如果有任何區別,我正在使用 docker 影像“haproxy:lts-alpine”。
uj5u.com熱心網友回復:
因為你的frontend配置:
frontend http
...
redirect scheme https if !{ ssl_fc }
HAProxy 正在將您的應用程式流量從 HTTP 重定向到 HTTPS。您可以在日志中檢查它,因為它回傳302HTTP 狀態代碼:
wc_haproxy | 172.29.0.1:35296 [03/Nov/2021:22:03:44.901] http http/<NOSRV> 0/-1/-1/-1/0 302 134 - - LR-- 1/1/0/0/0 0/0 "POST /register HTTP/1.1"
請考慮查看HAProxy 相關檔案。
所述POST 302重定向到GET轉換是一種常見的瀏覽器模式。請考慮閱讀這個 SO 問題。我認為這可能與您的問題有關。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/347902.html
