Run WordPress in Docker behind Apache Reverse Proxy

  apache, docker, docker-compose, reverse-proxy, wordpress

I want to run a wordpress installation in a docker container behind an apache reverse proxy. The apache should also handle ssl termination.

Docker Config:

version: '3.1'

services:

  wordpress:
    image: wordpress:5.5-php7.4-apache
    restart: always
    ports:
      - 8080:80
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: <user>
      WORDPRESS_DB_PASSWORD: <password>
      WORDPRESS_DB_NAME: wp1-db
    volumes:
      - ./wp1:/var/www/html
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: wp1-db
      MYSQL_USER: <user>
      MYSQL_PASSWORD: <password>
      MYSQL_RANDOM_ROOT_PASSWORD: '<password>'
    volumes:
      - ./db1/:/var/lib/mysql

apache config

<VirtualHost *:80>
    
    ServerName <servername>
    
    ProxyPreserveHost off
    ProxyPass               /       http://127.0.0.1:8080/
    ProxyPassReverse        /       http://127.0.0.1:8080/
    
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =<servername>/ [OR]
    RewriteCond %{SERVER_NAME} =<servername>
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

now when i enter my site under the given domain without ssl the site is at least showing up but with some cross origin errors in the console log but not loading some of the css files.

... has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

When i enter the site with ssl i am getting a ton of mixed content errors in the console.

Mixed Content: The page at '<URL>' was loaded over HTTPS, but requested an insecure script '<URL>'. This request has been blocked; the content must be served over HTTPS.

I guess i am missing headers for the reverse proxy and config in wordpress that content will be loaded via https ?

Thank you very much !!

EDIT:

When i add

RequestHeader set X-Forwarded-Port "443"
RequestHeader set X-Forwarded-Proto "https"

in the ssl conf i am getting rid of the mixed content errors but i cannot load content anymore.

GET https://<domain.name>:8080/wp-includes/css/dist/block-library/style.min.css?ver=5.6 net::ERR_SSL_PROTOCOL_ERROR

Is this setting correct and i am missing something in wordpress ?

Source: Docker Questions

LEAVE A COMMENT