WordPress behind a reverse proxy/ssl endpoint, slightly borked
-
I’ve just recently moved my blog — https://dogsofsf.com — behind a reverse proxy/ssl endpoint (nginx, also proxying a half-dozen other sites, each with their own ssl certificates) and set up a redirect from http to https, thus making my site https-all-the-time. It works beautifully for the most part, although I’ve had to overcome a couple of obstacles, but I have one vexing problem left.
First, what I’ve found so far, since I have never seen this information all in one place before. Hopefully someone can answer my question at the end, and we can make this thread a resource for people who want to do what I did.
1) In order to not get constant warnings that you are submitting an insecure form when you log in, search, or submit any other form (I assume the form submit buttons etc are coming through as http rather than https), you need to tell the blog to use the ‘HTTP_X_FORWARDED_PROTO’ header to determine SSL-ness. Stick this in your wp-config.php file:
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';
2) If you don’t want all of your comments to appear to have come from your proxy server, you have to tell wordpress that the remote server is really at the IP address from the header ‘HTTP_X_FOWARDED_FOR’. Again, in wp-config.php:
if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { $_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_X_FORWARDED_FOR"]; }
I’m stuck on the last problem: the site does not display as being secure. This is because a bunch of the image URLs on the front page are, for some reason, coming through as http rather than https. They get 301-ed to https but that doesn’t actually help. As an example, my front page currently has image tags like this on it:
https://dogsofsf.com/wp-content/uploads/2015/01/IMG_3283-600×418.jpg
https://dogsofsf.com/wp-content/uploads/2015/01/IMG_3289-600×558.jpg
etc. Note, no https.Now, my original thought was that I should change the ‘WordPress Address’ and ‘Site Address’ to ‘https://dogsofsf.com’ instead of ‘https://dogsofsf.com’. But that immediately broke the entire site and made it impossible for me to even load the admin — I had to restore from a backup, things were so bad — so I guess that’s not it? Or maybe there was something else I needed to do?
I would really appreciate any help.
Incidentally, it kind of boggles my mind that this stuff wouldn’t be a config option at the very least.
- The topic ‘WordPress behind a reverse proxy/ssl endpoint, slightly borked’ is closed to new replies.