多級代理 haproxy 傳遞X-Forwarded-Proto


有時候后端需要知道客戶端是用的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/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM