nginx配置upstream反向代理
http?{ ?... ?upstream?tomcats?{ ??server?192.168.106.176?weight=1; ??server?192.168.106.177?weight=1; ?} ?server?{ ??location?/ops-coffee/?{? ???proxy_pass?http://tomcats; ???proxy_set_header?Host?$host; ???proxy_set_header?X-Real-IP?$remote_addr; ???proxy_set_header?X-Forwarded-For?$proxy_add_x_forwarded_for; ???proxy_set_header?X-Forwarded-Proto?$scheme; ??} ?} }
稍不注意可能會落入一個proxy_pass加杠不加杠的陷阱,這里詳細說下proxy_pass http://tomcats與proxy_pass http://tomcats/的區別:
雖然只是一個/的區別但結果確千差萬別。分為以下兩種情況:
1.? 目標地址中不帶uri(proxy_pass http://tomcats)。此時新的目標url中,匹配的uri部分不做修改,原來是什么就是什么。
location?/ops-coffee/?{ ?proxy_pass?http://192.168.106.135:8181; } http://domain/ops-coffee/?-->??http://192.168.106.135:8181/ops-coffee/ http://domain/ops-coffee/action/abc?-->??http://192.168.106.135:8181/ops-coffee/action/abc
2.? 目標地址中帶uri(proxy_pass http://tomcats/,/也是uri),此時新的目標url中,匹配的uri部分將會被修改為該參數中的uri。
location?/ops-coffee/?{ ?proxy_pass?http://192.168.106.135:8181/; } http://domain/ops-coffee/?-->??http://192.168.106.135:8181 http://domain/ops-coffee/action/abc?-->??http://192.168.106.135:8181/action/abc
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END