如何在 Apache 中合并多个 ProxyPass 指令?

如何在 Apache 中合并多个 ProxyPass 指令?

由于我们使用的部署系统形式如下,我需要将 ProxyPass 配置保存在单独的文件中:

文件 1:

<VirtualHost *:80>
    <Location /qa1/>
        ProxyPass http://localhost:8800/qa1/
        ProxyPassReverse http://localhost:8800/qa1/
        ProxyPassReverseCookiePath / /qa1/
    </Location>
</VirtualHost>

文件 2:

<VirtualHost *:80>
    <Location /qa2/>
        ProxyPass http://localhost:8801/qa2/
        ProxyPassReverse http://localhost:8801/qa2/
        ProxyPassReverseCookiePath / /qa2/
    </Location>
</VirtualHost>

但 Apache 抱怨说:[警告]默认VirtualHost 在 80 端口上重叠,第一个优先

有任何想法是否/如何让 Apache 合并这两种配置?

答案1

使用Include

文件 1:qa1.conf

<Location /qa1/>
    ProxyPass http://localhost:8800/qa1/
    ProxyPassReverse http://localhost:8800/qa1/
    ProxyPassReverseCookiePath / /qa1/
</Location>

文件 2:qa2.conf

<Location /qa2/>
    ProxyPass http://localhost:8801/qa2/
    ProxyPassReverse http://localhost:8801/qa2/
    ProxyPassReverseCookiePath / /qa2/
</Location>

文件 3:vhost.conf

<VirtualHost *:80>
    Include qa1.conf
    Include qa2.conf
</VirtualHost>

答案2

只需单独保留 Location 指令

文件 qa1.conf

<Location /qa1/>
    ProxyPass http://localhost:8800/qa1/
    ProxyPassReverse http://localhost:8800/qa1/
    ProxyPassReverseCookiePath / /qa1/
</Location>

文件 qa2.conf

<Location /qa2/>
    ProxyPass http://localhost:8801/qa2/
    ProxyPassReverse http://localhost:8801/qa2/
    ProxyPassReverseCookiePath / /qa2/
</Location>

然后

<VirtualHost *:80>
    include qa1.conf 
    include qa2.conf
</VirtualHost>

相关内容