How to make Wordpress use HTTPS scheme when behind a ReverseProxy
I host Dockerized Wordpress. That means there is a front ReverseProxy that terminates the SSL tunnel and Proxies the requests to the Dockerized Wordpress through clear HTTP.
When a Wordpress is queried through clear HTTP, it builds all its assets URLs with HTTP scheme.
I want the Dockerized Wordpress to builds all its assets URLs with HTTPS scheme.
Set the header "X-Forwarded-Proto" to the "https" value
In order to achieve that, I have to fool it (to lie) and pretend it has been queried through HTTPS instead of clear HTTP.
For that, on the Dockerized Apache, I have to artificially set the header "X-Forwarded-Proto" to the "https" value.
In the ".htaccess" I have to :
# Artificially set "X-Forwarded-Proto" to "https" RequestHeader set X-Forwarded-Proto "https" RequestHeader set X-Forwarded-Port "443" # following is standard Wordpress htaccess rules RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]
And in the "wp-config.php" file:
$_SERVER['HTTPS'] = 'on';