反向代理背后的WordPress

我们的组织正在重build它的网站。 有人在新的服务器上build立了新的站点。 可以在/ etc / hosts中input条目后访问它。 当以这种方式访问​​时,完美的作品。

但是由于大多数参与者都不太擅长电脑,所以我决定设置一个反向代理

我没有访问该网站,也没有服务器女巫主办。 我有一个WordPress的编辑器帐户安装在那里。

我已经在我的私人服务器的/ etc / hosts中设置了一个条目,并使用以下configuration设置了反向代理服务器,我的服务器在Debian stable下运行apache-2.2:

<VirtualHost *:80> ServerName xxx.xxx.xxx.xxx ProxyRequests off ProxyPass /some/prefix/ http://site.example.com/ ProxyPassReverse /some/prefix/ http://site.example.com/ ProxyHTMLURLMap http://site.example.com/ http://xxx.xxx.xxx.xxx/some/prefix/ <Location /some/prefix/> SetOutputFilter INFLATE;proxy-html;DEFLATE ProxyHTMLURLMap http://site.example.com/ /some/prefix/ </Location> ProxyPassReverseCookieDomain site.example.com xxx.xxx.xxx.xxx ProxyPassReverseCookiePath / /some/prefix/ ProxyHTMLExtended On </VirtualHost> 

几乎一切正常。 我无法创build新post(文本编辑器无法正常加载)。 Iceweasel的(Firefox)开发者模式说:

 (...) [00:13:33.365] GET http://xxx.xxx.xxx.xxx/some/prefix/wp-includes/js/tinymce/langs/pl.js?wp-mce-4107-20141130 [HTTP/1.1 404 Not Found 399ms] (...) [00:13:33.648] Failed to load: http://xxx.xxx.xxx.xxx/some/prefix/wp-includes/js/tinymce/langs/pl.js [00:13:46.733] POST http://xxx.xxx.xxx.xxx/wp-admin/admin-ajax.php [HTTP/1.1 404 Not Found 102ms] 

我省略了非错误。 在我看来,Apache并没有重写一些东西。 有任何想法吗?

在这里,我的工作configuration为您的情况。

 <VirtualHost *:80> ServerName proxy.example.net ProxyRequests off ProxyPass /some/prefix/ http://backend.example.net/ ProxyPassReverse /some/prefix/ http://backend.example.net/ <Location /some/prefix/> ProxyHTMLEnable On ProxyHTMLExtended On ProxyHTMLLinks a href ProxyHTMLLinks area href ProxyHTMLLinks link href ProxyHTMLLinks img src longdesc usemap ProxyHTMLLinks object classid codebase data usemap ProxyHTMLLinks q cite ProxyHTMLLinks blockquote cite ProxyHTMLLinks ins cite ProxyHTMLLinks del cite ProxyHTMLLinks form action ProxyHTMLLinks input src usemap ProxyHTMLLinks head profile ProxyHTMLLinks base href ProxyHTMLLinks script src for ProxyHTMLLinks iframe src RequestHeader unset Accept-Encoding ProxyHTMLURLMap /wp-admin/ /some/prefix/wp-admin/ ProxyHTMLURLMap \/wp-admin\/ \/some\/prefix\/wp-admin\/ ProxyHTMLURLMap http://backend.example.net/ http://proxy.example.net/some/prefix/ </Location> ProxyPassReverseCookieDomain backend.example.net proxy.example.net ProxyPassReverseCookiePath / /some/prefix/ # LogLevel warn proxy_html:trace3 ErrorLog ${APACHE_LOG_DIR}/errorprox.log CustomLog ${APACHE_LOG_DIR}/accessprox.log combined </VirtualHost> 

一些解释

  • 我必须设置ProxyHTMLLinks因为在下面的apache日志中有一些错误。 configuration从这个博客文章被撕掉。

    [Sun Dec 21 23:02:49.053825 2014] [proxy_html:trace1] [pid 3368:tid 140385487116032] mod_proxy_html.c(823):[client 36.71.243.192:56711]没有链接configuration:没有代理htmlfilter做

  • 参数RequestHeader unset Accept-Encoding用于replace参数SetOutputFilter INFLATE;proxy-html;DEFLATE 。 代理和真正的WordPress之间的stream量的影响是没有压缩。 看到这个页面的细节。

  • URL wp-admin/admin-ajax.php是由javascript定义和调用的。 参数ProxyHTMLExtended On应该做这个工作。

  • URL wp-admin/admin-ajax.php定义没有域(你可以看到它,当在Firefox中点击查看页面源)。 这导致参数http://site.example.com/ /some/prefix/不匹配这个string。 所以,我设置了新的参数

    • ProxyHTMLURLMap /wp-admin/ /some/prefix/wp-admin/用于常规string。
    • ProxyHTMLURLMap \/wp-admin\/ \/some\/prefix\/wp-admin\/用于转义string。