Recently, I upgraded my Raspberry Pi that serves this website, my instance of EmonCMS, and a few other projects I use at home.
As a part of that, I also use an instance of Home Assistant on a different Raspberry Pi.
These things need to be available externally, which I struggled with at first. WordPress didn’t like responding in HTTP when it was hit with proxied/forwarded HTTPS requests over HTTP. This is post is to document what I had to do to fix this when future me has to fix the same problem.
As you can see, I used the first Raspberry Pi running Home Assistant responds to the domain ‘ha.philipahlers.com’. Nginx Proxy Manager sees other domains, like ’emon.philipahlers.com’ and ‘philipahlers.com’ and forwards them to the other Raspberry Pi. It’s getting HTTPS requests on port 443, handles the SSL certificates, and forwards the request, now HTTP and port 80 to that second Raspberry Pi.
So to fix WordPress – I had to add some code to the WordPress wp-config.php file located in the WordPress installation folder:
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
$_SERVER['HTTPS'] = 'on';
}
This lets WordPress respond to requests forwarded from HTTPS over HTTP correctly.
Leave a Reply
You must be logged in to post a comment.