代理到负载均衡器自动添加附加路径

代理到负载均衡器自动添加附加路径

我在 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/,显然不存在。

我尝试在线搜索,但找不到任何相关结果。有类似经历的人能解释一下为什么会出现这种行为吗?谢谢

答案1

我找到了问题所在。原来这是因为指令的顺序。较短的必须放在最前面,如下所示:

<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>

相关内容