[英]Apache Reverse Proxy to a Wordpress site passes subpath when it shouldn't
I've been trying to set up a reverse proxy on a main website to a blog site of the url format 我一直在尝试在主网站上将反向代理设置为url格式的博客网站
example.com/blog -> blog.example.com example.com/blog-> blog.example.com
example.com/blog is on an Apache instance and in the httpd.conf
I have added the following. example.com/blog在Apache实例上,并且在
httpd.conf
中添加了以下内容。
SSLProxyEngine on
ProxyPreserveHost Off
ProxyRequests Off
ProxyPassMatch /blog https://blog.example.com
ProxyPassReverse /blog https://blog.example.com
This all works but it keeps 404ing. 所有这些都有效,但是仍然保持404状态。 The good news is it is actually reverse proxying correctly because it grabs the 404 page of the blog.
好消息是它实际上是正确的反向代理,因为它可以获取博客的404页。
After looking at the apache access logs I found that it is passing the subpath for whatever reason /blog
to blog.example.com
so its fetching blog.example.com/blog
. 查看apache访问日志后,我发现它出于某种原因将子路径
/blog
传递给blog.example.com
因此其获取blog.example.com/blog
。 When users navigate to /blog
, it does 404 naturally. 当用户导航到
/blog
,它自然会执行404。 However, my understanding was when setting up ProxyPassReverse
is it would make the request at what was specified so in my above case it should be requesting blog.example.com
and not passing the /blog
at the end. 但是,我的理解是在设置
ProxyPassReverse
,它将按指定的内容发出请求,因此在我上面的情况下,它应该是请求blog.example.com
而不是最后传递/blog
。
Here is the snippet from the documentation that confirms the above in how it should work: 以下是文档的片段,该片段确认了上面的工作方式:
For example, suppose the local server has address http://example.com/ ;
例如,假设本地服务器的地址为http://example.com/ ; then
然后
ProxyPass /mirror/foo/ http://backend.example.com/
ProxyPassReverse /mirror/foo/ http://backend.example.com/
ProxyPassReverseCookieDomain backend.example.com public.example.com
ProxyPassReverseCookiePath / /mirror/foo/
will not only cause a local request for the http://example.com/mirror/foo/bar to be internally converted into a proxy request to http://backend.example.com/bar (the functionality which ProxyPass provides here).
不仅会导致对http://example.com/mirror/foo/bar的本地请求在内部转换为对http://backend.example.com/bar的代理请求(ProxyPass在此处提供的功能) 。
Any ideas why this might be? 任何想法为什么会这样? Worst case I might try to add a redirect or a rewrite so
/blog
goes to the homepage but I do have my permalinks set up in such a way that the /blog
is in the slug of articles. 最坏的情况是我可能尝试添加重定向或重写,以使
/blog
转到主页,但我的永久链接的设置方式确实使/blog
在文章中。
FYI I am using Apache 2.2. 仅供参考,我正在使用Apache 2.2。
I'm an idiot. 我是个白痴。 I was using
ProxyPassMatch
instead of ProxyPass
. 我正在使用
ProxyPassMatch
而不是ProxyPass
。 Ugh. 啊。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.