如何停止 HAProxy 将我的 POST 转换为 GET
How to stop HAProxy converting my POST to GET
出于某种原因,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”,如果这有什么不同的话。
因为你的 frontend
配置:
frontend http
...
redirect scheme https if !{ ssl_fc }
HAProxy 正在将您的应用程序流量从 HTTP 重定向到 HTTPS。您可以在日志中查看它,因为它返回 302
HTTP 状态代码:
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 relevant documentation。
POST
302
重定向到 GET
转换是一种常见的浏览器模式。请考虑阅读 this SO question。我认为这可能与您的问题有关。
出于某种原因,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”,如果这有什么不同的话。
因为你的 frontend
配置:
frontend http
...
redirect scheme https if !{ ssl_fc }
HAProxy 正在将您的应用程序流量从 HTTP 重定向到 HTTPS。您可以在日志中查看它,因为它返回 302
HTTP 状态代码:
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 relevant documentation。
POST
302
重定向到 GET
转换是一种常见的浏览器模式。请考虑阅读 this SO question。我认为这可能与您的问题有关。