有時候后端需要知道客戶端是用的http請求還是https請求,所以一般在haproxy加上一個X-Forwarded-Proto頭
http-request set-header X-Forwarded-Proto http if !{ ssl_fc } http-request set-header X-Forwarded-Proto https if { ssl_fc }
但是如果haproxy前面還有反代並且傳遞了X-Forwarded-Proto頭,那么這么做就會把haproxy前面的反代傳遞的X-Forwarded-Proto頭覆蓋掉
這種情況可以用haproxy的強大的acl來處理
acl h_xfp_exists req.hdr(X-Forwarded-Proto) -m found http-request set-header X-Forwarded-Proto http if !{ ssl_fc } !h_xfp_exists http-request set-header X-Forwarded-Proto https if { ssl_fc } !h_xfp_exists
參考文檔:
https://www.haproxy.com/documentation/hapee/1-8r1/traffic-management/http-rewrite/
https://www.haproxy.com/documentation/hapee/1-8r1/traffic-management/acls/