Blocked / mixed content with WordPress/ apache proxypass

apache-2.4lets-encryptproxypass

I'm trying to setup an apache reverse proxy to a specific port (8001) which links to a wordpress docker container:

$ docker ps
CONTAINER ID        IMAGE                           COMMAND                  CREATED             STATUS              PORTS                      NAMES
9592d33ed6c1        wordpress:5.5.0-php7.3-apache   "docker-entrypoint..."   23 seconds ago      Up 21 seconds       0.0.0.0:8001->80/tcp       martynbiz_wordpress_1
7c0d046560d6        mysql:5.7                       "docker-entrypoint..."   25 seconds ago      Up 23 seconds       3306/tcp, 33060/tcp        martynbiz_db_1

Below are my apache config file:

/etc/apache2/sites-available/martynbiz.conf

<Virtualhost *:80>
    ServerName        www.martyn.biz
    ServerAlias        martyn.biz
    ProxyRequests     Off
    ProxyPreserveHost On
    AllowEncodedSlashes NoDecode

    SSLProxyEngine On
    SSLProxyCheckPeerCN on
    SSLProxyCheckPeerExpire on

    <Proxy http://localhost:8001/*>
      Order deny,allow
      Allow from all
    </Proxy>

    ProxyPass         /  http://localhost:8001/ nocanon
    ProxyPassReverse  /  http://localhost:8001/

    #RewriteEngine on
    #RewriteCond %{SERVER_NAME} =martyn.biz
    #RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.martyn.biz [OR]
RewriteCond %{SERVER_NAME} =martyn.biz
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</Virtualhost>

/etc/apache2/sites-available/martynbiz-le-ssl.conf

<IfModule mod_ssl.c>
<Virtualhost *:443>
    ServerName        www.martyn.biz
    ServerAlias        martyn.biz
    ProxyRequests     Off
    ProxyPreserveHost On
    AllowEncodedSlashes NoDecode

    SSLProxyEngine On
    SSLProxyCheckPeerCN on
    SSLProxyCheckPeerExpire on

    <Proxy http://localhost:8001/*>
      Order deny,allow
      Allow from all
    </Proxy>

    ProxyPass         /  http://localhost:8001/ nocanon
    ProxyPassReverse  /  http://localhost:8001/

    Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/martyn.biz/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/martyn.biz/privkey.pem
</Virtualhost>
</IfModule>

My certificate seems valid, and the reverse proxy is linking the container with the domain name. However, I'm getting blocked mixed content so the stylesheets etc don't diplay. If I remove all the SSL stuff from the config files, and use HTTP instead everything looks OK. I've never had this issue before with setting up SSL certificates – but in the past I've not used a reverse proxy. I suspect that the issue is with that and HTTP/HTTPS wronly configured in apache?

Best Answer

Fixed by adding the following to the very top (after the <?php ) of wp-config.php

if ( (!empty( $_SERVER['HTTP_X_FORWARDED_HOST'])) || (!empty( $_SERVER['HTTP_X_FORWARDED_FOR'])) ) { $_SERVER['HTTPS'] = 'on'; }
Related Topic