我有一个配置站点配置的任务,例如:
1) * 必须重定向到后端
2) /测试必须显示主 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 测试页面,总是重定向到平衡器
答案1
典型的做法是/test
使用感叹号从反向代理!中排除 URL 路径ProxyPass
指示。
然后/test
URL 将直接从您的 VirtualHost 条目提供,并将显示相对于 的内容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>