如何排除 Apache Mod_proxy 的 URL?

Mug*_*hil 34 linux mod-rewrite tomcat mod-proxy apache-2.2

我们使用 mod_proxy 模块作为负载均衡器配置了两个 Apache 服务器作为前端和 4 个 tomcat 服务器作为后端。现在,我们想从 mod_proxy 负载均衡器中排除单个 tomcat url。有什么办法或规则可以排除吗?

代理平衡器设置:

<Proxy balancer://backend-cluster1>
   BalancerMember http://10.0.0.1:8080 loadfactor=1 route=test1 retry=10
   BalancerMember http://10.0.0.2:8080 loadfactor=1 route=test2 retry=10
</Proxy>
Run Code Online (Sandbox Code Playgroud)

Ala*_*ack 51

您在完整的 ProxyPass 语句之前使用感叹号 (!) 从 mod_proxy 中排除路径,您的示例缺少该语句 - 它看起来像ProxyPass /path balancer://backend-cluster1. 因此,要排除路径,请添加:

ProxyPass /my/excluded/path !
Run Code Online (Sandbox Code Playgroud)

ProxyPass /my balancer://backend-cluster1
Run Code Online (Sandbox Code Playgroud)

  • 当使用 ProxyPass 在那里显示聊天服务器时,使用此答案非常适合允许 LetsEncrypt 进入虚拟主机的默认 .well-known 文件夹位置。在其他指令之前添加: ProxyPass /.well-known ! (2认同)

小智 7

除了 Alastair McCormack 的回答:如果您使用<Location>,则需要在下面而不是之前放置异常:

<Location /my/>
    ProxyPass balancer://backend-cluster1
</Location>

<Location /my/excluded/path/>
    ProxyPass !
</Location>
Run Code Online (Sandbox Code Playgroud)


Pab*_*blo -2

您可以在代理指令之上进行重写,当用户尝试访问您要排除的 url 时,这将给用户带来 404 错误。您需要启用 rewrite_module。

<Location ~ ^/urltoblock($|/)>
   RewriteEngine On 
   RewriteRule .* - [L,R=404]
</Location>
Run Code Online (Sandbox Code Playgroud)