How to put wordpress site behind AWS load balancer

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

if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
    $_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/

Leave a Comment