Apache 反向代理配置 - 子域
Apache Reverse Proxy configuration - Subdomains
我正在尝试将 Apache 服务器配置为具有 2 个使用反向代理的子域。我能够将流量重定向到第一个子域 (first.example.com) 并成功从 https 站点检索内容。但是,每当我尝试访问第二个子域时,我最终会从第一个子域获取内容,并且由于路由与我的本地网站不匹配,我得到一个未找到的页面。
我想知道我可以从我当前的配置中调整什么,以便我可以从我的本地主机站点获取内容。
这是我当前的配置:
<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://whosebug.com
ProxyPassReverse /first https://whosebug.com
ProxyPassMatch ^/(.*)$ https://whosebug.com/
</VirtualHost>
<VirtualHost second.example.com:80>
ServerName second.example.com
ProxyPass /site http://localhost/site
ProxyPassReverse /site http://localhost/site
ProxyPassMatch ^/(.*)$ http://localhost/site/
</VirtualHost>
非常感谢您!
此致!
埃德加·马丁内斯。
您当前的配置与自身冲突。 ProxyPass and ProxyPassMatch 做同样的事情(在正则表达式中)但是你用不同的规则声明它。
ProxyPass /site http://localhost/site
规则说:任何访问 http://second.example.com/site
的人都将收到来自 http://localhost/site
的内容。如果您访问 http://second.example.com/foo
,您将一无所获。
匹配线
ProxyPassMatch ^/(.*)$ http://localhost/site/
规则说:访问 http://second.example.com/site
的任何人都将收到来自 http://localhost/site/site
的内容。如果您访问 http://second.example.com/foo
,您会得到 http://localhost/site/foo
。
如果您使用 Match 版本 (regex),那么对于没有 regex 版本的反向规则,您也不走运。不过,我不确定您是否真的需要反向规则。
至于为什么你的第二个请求得到了第一个请求的结果...我不知道。
我正在尝试将 Apache 服务器配置为具有 2 个使用反向代理的子域。我能够将流量重定向到第一个子域 (first.example.com) 并成功从 https 站点检索内容。但是,每当我尝试访问第二个子域时,我最终会从第一个子域获取内容,并且由于路由与我的本地网站不匹配,我得到一个未找到的页面。
我想知道我可以从我当前的配置中调整什么,以便我可以从我的本地主机站点获取内容。
这是我当前的配置:
<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://whosebug.com
ProxyPassReverse /first https://whosebug.com
ProxyPassMatch ^/(.*)$ https://whosebug.com/
</VirtualHost>
<VirtualHost second.example.com:80>
ServerName second.example.com
ProxyPass /site http://localhost/site
ProxyPassReverse /site http://localhost/site
ProxyPassMatch ^/(.*)$ http://localhost/site/
</VirtualHost>
非常感谢您!
此致!
埃德加·马丁内斯。
您当前的配置与自身冲突。 ProxyPass and ProxyPassMatch 做同样的事情(在正则表达式中)但是你用不同的规则声明它。
ProxyPass /site http://localhost/site
规则说:任何访问 http://second.example.com/site
的人都将收到来自 http://localhost/site
的内容。如果您访问 http://second.example.com/foo
,您将一无所获。
匹配线
ProxyPassMatch ^/(.*)$ http://localhost/site/
规则说:访问 http://second.example.com/site
的任何人都将收到来自 http://localhost/site/site
的内容。如果您访问 http://second.example.com/foo
,您会得到 http://localhost/site/foo
。
如果您使用 Match 版本 (regex),那么对于没有 regex 版本的反向规则,您也不走运。不过,我不确定您是否真的需要反向规则。
至于为什么你的第二个请求得到了第一个请求的结果...我不知道。