Apache反向代理配置 - 子域

时间:2017-09-06 00:23:26

标签: apache reverse-proxy virtualhost

我正在尝试将Apache服务器配置为使用反向代理的2个子域。我能够将流量重定向到第一个子域(first.example.com)并成功从https站点检索内容。但是,每当我尝试访问第二个子域时,我最终都会从第一个子域获取内容,并且由于路由与我的本地网站不匹配,因此我找到了一个未找到的页面。

我想知道我可以从当前配置调整哪些内容,以便从localhost网站获取内容。

这是我目前的配置:

<Proxy *>
Require all granted
</Proxy>

SSLProxyEngine On
ProxyRequests Off
SSLProxyCheckPeerCN off
SSLProxyCheckPeerExpire off
SSLInsecureRenegotiation on
SSLProxyVerify none
SSLVerifyClient none
SSLProxyCheckPeerName off

<VirtualHost first.example.com:80>
    ServerName first.example.com
    ProxyPass /first https://stackoverflow.com
    ProxyPassReverse /first https://stackoverflow.com
    ProxyPassMatch ^/(.*)$ https://stackoverflow.com/$1

</VirtualHost>

<VirtualHost second.example.com:80>
    ServerName second.example.com
    ProxyPass /site http://localhost/site
    ProxyPassReverse /site http://localhost/site
    ProxyPassMatch ^/(.*)$ http://localhost/site/$1
</VirtualHost>

非常感谢你!

最诚挚的问候!

埃德加·马丁内斯。

1 个答案:

答案 0 :(得分:1)

您当前的配置与自身冲突。 ProxyPassProxyPassMatch执行相同的操作(在正则表达式中),但您使用不同的规则声明它们。

ProxyPass /site http://localhost/site

规则说明:访问http://second.example.com/site的任何人都会收到来自http://localhost/site的内容。如果您访问http://second.example.com/foo,则什么也得不到。

匹配线

ProxyPassMatch ^/(.*)$ http://localhost/site/$1

规则说明:访问http://second.example.com/site的任何人都会收到来自http://localhost/site/site的内容。如果您访问http://second.example.com/foo,则会获得http://localhost/site/foo

如果您使用匹配版本(正则表达式),那么对于没有正则表达式版本的反向规则,您也不幸运。虽然,我不确定你真的需要反向规则。

至于为什么你的第二个请求从第一个请求得到结果......我不知道。

相关问题