Apache-2.2

httpd 重定向到主 apache 測試頁面

  • May 23, 2018

我有一個任務來配置站點配置,例如:

    • 必須重定向到後端
  1. /test必須顯示主 apache 頁面

我嘗試過一些案例:

<VirtualHost *:*>
<Proxy balancer://mycluster>
   BalancerMember http://localhost:8080/sample
   BalancerMember http://localhost:8090/sample
   BalancerMember http://localhost:9080
</Proxy>
   ProxyPreserveHost On
   ProxyPass /test http://localhost:80
   ProxyPassReverse /test http://localhost:80
   ProxyPass / balancer://mycluster/
   ProxyPassReverse / balancer://mycluster/
</VirtualHost>

或者

ProxyRequests On 
<Proxy *> 
   Order deny,allow 
   Allow from all 
 </Proxy> 
 <Proxy balancer://mycluster>
               BalancerMember http://localhost:8080/sample
               BalancerMember http://localhost:8090/sample
               BalancerMember http://localhost:9080 
  </Proxy>

   ProxyPreserveHost On 
   ProxyPass /test http://localhost:80 
   ProxyPassReverse /test http://localhost:80 
   ProxyPass / balancer://mycluster/ 
   ProxyPassReverse / balancer://mycluster/

在這兩種情況下,我都無法訪問 apache 測試頁面,總是重定向到平衡器

典型的做法是通過在指令 中/test使用驚嘆號從反向代理中排除URL 路徑。!ProxyPass

然後/testURL 將直接從您的 VirtualHost 條目提供,並顯示相對於 a 的內容DocumentRoot,或者您​​可以使用 .將/test路徑映射到文件系統上的特定位置Alias

VirtualHost *:*>
<Proxy balancer://mycluster>
   BalancerMember http://localhost:8080/sample
   BalancerMember http://localhost:8090/sample
   BalancerMember http://localhost:9080
</Proxy>
   ProxyPreserveHost On

   # Exclude /test from the reverse proxy
   ProxyPass !/test 

   # Map /test to the CentOS directory with the test index.html
   Alias /test  /usr/share/httpd/noindex

   # Alternatively create /var/www/html/test and set the following DocumentRoot
   # DocumentRoot /var/www/html

   ProxyPass / balancer://mycluster/
   ProxyPassReverse / balancer://mycluster/


</VirtualHost>

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