
我正在使用 HAProxy 來平衡幾個 Web 伺服器的負載(HTTP 模式)。 Web 伺服器是嚴格動態的,即沒有任何靜態內容,只有 Web 服務。
該類型的 URL(類似)
http://192.168.5.10:8080/small
http://192.168.5.10:8080/medium
http://192.168.5.10:8080/large
acl
現在,當我配置 HAProxy 將傳入請求轉發到幾台電腦上的這 3 個 url 時,我使用和path_end
/指定 url_path path_beg
,但在發出請求時出現Not Found on Accelerator
錯誤,這使得更難找出問題。
以下是我正在使用的配置。此外,它不會記錄任何錯誤。
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
maxconn 4096
user haproxy
group haproxy
daemon
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 10000
srvtimeout 10000
frontend http_proxy
bind 192.168.5.9:8888
acl is_small path_end -i small
acl is_medium path_end -i medium
acl is_large path_end -i large
use_backend web_server_small if is_small
use_backend web_server_medium if is_medium
use_backend web_server_large if is_large
backend web_server_small
mode http
balance roundrobin
option httpclose
server web_1 192.168.5.10:8080 check
server web_2 192.168.5.11:8080 check
backend web_server_medium
mode http
balance roundrobin
option httpclose
server web_1 192.168.5.12:8080 check
server web_2 192.168.5.13:8080 check
backend web_server_large
mode http
balance roundrobin
option httpclose
server web_1 192.168.5.14:8080 check
server web_2 192.168.5.15:8080 check
是否可以使用 url_path 將請求從 HAProxy 傳送到 web_server?
如果 HAProxy 收到它http://192.168.5.2:80/small
,則將請求傳送到 Web 伺服器http://192.168.5.10:8080/small
答案1
由於您的路徑包含在 URL 的開頭,因此為什麼不使用 path_beg,建議將 path_end 用於檔案副檔名。
acl is_small path_beg -i /small acl is_medium path_beg -i /medium acl is_large path_beg -i /large
答案2
HTTP請求的路徑是總是交給後端伺服器,即
GET /small HTTP/1.1
將在 HAproxy 後面可見,就像該請求一樣。如果您懷疑這以某種方式被截斷為
GET / HTTP/1.1
在 HAproxy 後面的伺服器上,您應該使用以下命令檢查這一點
tcpdump -i any port 8080 -As1024 | grep GET
在該伺服器上並觀察入站GET
請求。
我假設你期望 HAproxy插入URI 前面的內容,例如
server web_1 192.168.5.14:8080/my/path check
會將 的 請求 轉換/small
為 的 請求/my/path/small
。這可以透過使用選項來實現reqrep
,請參閱文件了解詳情。