Wordpress behind reverse proxy

Our organization is remaking it's site. Someone had set up new site on new server. It can be accessed after putting an entry in /etc/hosts. And works perfectly when accessed this way.

But since most of the people involved, are not good with computers I've decided to setup a reverse proxy.

I don't have access to the site nor the server witch hosts it. I have an editor account on Wordpress installed there.

I've put an entry in /etc/hosts of my private server and setup reverse proxy with following config, my server is running apache-2.2 under Debian stable:

<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>

Almost everything works. I can't make new posts(the text editor does not load properly). Iceweasel's(Firefox) developer mode says:

(...)
[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]

I've omitted non errors. It seems to me that Apache is not rewriting something. Any ideas?


Here my working config for your case.

<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>

Some explanations

  • I have to set ProxyHTMLLinks because there are some errors in apache log below. The configuration was ripped from this blog post.

    [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] No links configured: nothing for proxy-html filter to do

  • Parameter RequestHeader unset Accept-Encoding was used to substituting parameter SetOutputFilter INFLATE;proxy-html;DEFLATE. The effect is traffic between proxy and real wordpress wasn't compressed. See this page for the details.

  • URL wp-admin/admin-ajax.php was defined and called by javascript. Parameter ProxyHTMLExtended On should do this job.

  • URL wp-admin/admin-ajax.php defined without domain (you can see it when clicked View Page Source in Firefox). This caused parameter http://site.example.com/ /some/prefix/ doesn't match this string. So, I set new parameter

    • ProxyHTMLURLMap /wp-admin/ /some/prefix/wp-admin/ for regular string.
    • ProxyHTMLURLMap \/wp-admin\/ \/some\/prefix\/wp-admin\/ for escaped string.