Apache2:如何使用不同的端口代理相同的 URL?

Apache2:如何使用不同的端口代理相同的 URL?

我们有多个不同的 /apex 实例。现在我们想通过 Apache2-Server 代理请求,如下所示:

request for instance1: http://proxy:8080/apex -> http://apex1:8080
request for instance2: http://proxy:8081/apex -> http://apex2:8080

这可以通过以下VirtualHost 解决。

<VirtualHost *:8080>
ProxyPass /apex/ http://apex1:8080/apex/
ProxypassReverse /apex/ http://apex1:8080/apex/
</VirtualHost>

<VirtualHost *:8081>
ProxyPass /apex/ http://apex2:8080/apex/
ProxypassReverse /apex/ http://apex2:8080/apex/
</VirtualHost>

但如果启用另一个虚拟主机则停止工作,就像其他 VirtualHosts 覆盖了 <VirtualHost> 匹配器

Alias /server-info /opt/www/
<VirtualHost *:*>
        <Directory "/srv/www/">
                Allow from all
                AuthType Basic
                AuthName "Password Required"
                Require valid-user
                AuthUserFile /etc/apache2/.htpasswd
                DirectoryIndex  side.html
        </Directory>
</VirtualHost>

如何解决这个问题?

答案1

问题已解决,使用以下配置

Alias /server-info /opt/www/
<VirtualHost 127.0.0.1:9000>
        <Directory "/srv/www/">
                Allow from all
                AuthType Basic
                AuthName "Password Required"
                Require valid-user
                AuthUserFile /etc/apache2/.htpasswd
                DirectoryIndex  side.html
        </Directory>
</VirtualHost>

ProxyPass /server-info/ http://127.0.0.1:9000/server-info-new/
ProxypassReverse /server-info/ http://127.0.0.1:9000/server-info-new/

通过 proxypass /server-info 可以从任意端口访问

相关内容