We have an old wordpress site hosted on an AWS EC2 linux server that I am trying to put behind a load balancer so I can use HTTPS and WAF. I am a somewhat experienced sysadmin but am very new to wordpress. I am having trouble getting the content to load over HTTPS while at the same time not getting into a redirect loop between the load balancer and the server.

I have the load balancer setup to talk to the server on port 80 and if WP_SITEURL/WP_HOME is set to http://, I get a bunch of mixed content errors in the chrome dev console because it is trying to load scripts and css over http. If I change WP_SITEURL/WP_HOME to https://, it creates a redirect loop because wordpress keeps trying to redirect the load balancer, which is trying to communicate on port 80, to https.

Is there a way to allow the load balancer to reach the server on port 80 while still having the base URL for resources, scripts, etc, be https?

1 Answer 1


When WordPress is behind https proxy (your load balancer) it doesn't know that https is enabled. Proxy is working through https (443 port) but communication between proxy and WordPress is through http (80 port). For WordPress traffic is through http, that's why you get redirect loop from https to http (by WordPress) and again from http to https (by proxy). You need to force WordPress to start working on https.

Paste this line into your wp-config.php

$_SERVER['HTTPS'] = 'on';

Sometimes proxies sent additional header HTTP_X_FORWARDED_PROTO to WordPress to let know that original traffic is on https. You can use it to be a little more flexible

    $_SERVER['HTTPS'] = 'on';

Change WP_SITEURL and WP_HOME to use https. And replace all links in the database to https.

Reference: https://developer.wordpress.org/reference/functions/is_ssl/

  • 1
    Thanks! That worked but I am no longer able to access the wp-admin page as after logging in I get a 403 forbidden... any ideas?
    – Pathead
    Commented Sep 9, 2020 at 12:50
  • @Pathead I had the exact same problem. Eventually it was solved by deleting the entire /var/www/html directory and letting WordPress create it again.
    – Tomer
    Commented Aug 14, 2021 at 12:40
  • Deleting cookies (for example from the Application tab in Chrome dev tools) and logging in again might address such a 403 error. Commented Oct 13, 2022 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.