Apache-2.4

代理負載均衡器自動添加額外路徑

  • May 5, 2021

我在 Redhat 7.9 上執行 httpd 2.4.6。我正在嘗試將 ProxyPass 與 Balancer 一起使用。這是我的配置。

平衡器

<Proxy balancer://mycluster>
   BalancerMember http://10.10.12.103:8080
   BalancerMember http://10.10.12.107:8080
</Proxy>

虛擬主機

<VirtualHost *:8080>

   ServerName      www.abcdef.com
   DocumentRoot "/app/httpd/html"

   <Location /heartbeat >
   </Location>

   <Location /up >
       ProxyPass balancer://mycluster/myapp1
       ProxyPassReverse balancer://mycluster/myapp1
   </Location>
   <Location /myapp1 >
       ProxyPass balancer://mycluster/myapp1
       ProxyPassReverse balancer://mycluster/myapp1
   </Location>
   <Location / >
       ProxyPass balancer://mycluster/myapp1
       ProxyPassReverse balancer://mycluster/myapp1
   </Location>

</VirtualHost>

我希望所有 3 條路徑:/、/myapp1、/up 都可以傳遞給我的後端伺服器上的 /myapp1。但是 /myapp1 和 /up 出現 404 錯誤。

我檢查了 tomcat 訪問日誌廣告,發現在 url 的末尾添加了一些內容:

[03/May/2021:22:02:45 +0000]|10.10.55.55|10.29.9.6||-|http-bio-8076-exec-4|0|10.10.55.55|-|-|"-"|"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0"|"GET /myapp1myapp1/ HTTP/1.1"|404|-
[03/May/2021:22:03:01 +0000]|10.10.55.55|10.29.9.6||-|http-bio-8076-exec-5|0|10.10.55.55|-|-|"-"|"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0"|"GET /myapp1up/ HTTP/1.1"|404|-

url 改變了:/up 到 /myapp1up/,/myapp1 到 /myapp1myapp1/,顯然不存在。

我試圖在網上研究並沒有找到任何結果。有這樣的經驗的人可以闡明為什麼它有這種行為嗎?謝謝

我解決了這個問題。原來是因為指令的順序。較短的必須像這樣排在第一位:

<VirtualHost *:8080>

   ServerName      www.abcdef.com
   DocumentRoot "/app/httpd/html"

   <Location /heartbeat >
   </Location>

   <Location / >
       ProxyPass balancer://mycluster/myapp1
       ProxyPassReverse balancer://mycluster/myapp1
   </Location>
   <Location /up >
       ProxyPass balancer://mycluster/myapp1
       ProxyPassReverse balancer://mycluster/myapp1
   </Location>
   <Location /myapp1 >
       ProxyPass balancer://mycluster/myapp1
       ProxyPassReverse balancer://mycluster/myapp1
   </Location>

</VirtualHost>

引用自:https://serverfault.com/questions/1062459