Fix WordPress HTTPS issues with EC2 when behind an Amazon Load Balancer?

Posted by
December 28, 2018

When running WordPress (or other PHP scripts) behind Amazon’s EC2 Load Balancer, the scripts do not realize they are being run on the https:// protocol and results in issues such as endless redirect loops, and HTTPS warnings (“Some content on this page is being requested in a non-secure way…”).

To solve this issue we have a solution.

For NGINX Server:

For rewrite setup, you should add the following under the server block:

if ($http_x_forwarded_proto != 'https') {
    rewrite ^ https://$host$request_uri? permanent;
}

And for setting the HTTPS param you should add the following under the location ~ \.php$ block:

if ($http_x_forwarded_proto = 'https') {
    set $fe_https 'on';
}
fastcgi_param HTTPS $fe_https;

 

 

read more