peppeocchi
peppeocchi

Reputation: 824

Https on Elastic Beanstalk - wordpress

I have an annoying issue with https on a wordpress website running on aws eb single instance.

I have the same website in a vps, https works fine, styles and css are served via https. Just to be sure (I've spent 2 days trying to figure out what's wrong) few minutes ago I deployed on eb a copy of the website - editing only the database settings.

So, the issue is that in eb if I go to https://mywebsite.com the page is "broken", styles and scripts are server through http.

In the vps if I go to https://mywebsite.com styles and scripts are https://mywebsite.com/styles/style.css, in eb styles and scripts are http://mywebsite.com/styles/style.css.

Why is this happening and how can I fix that?

I've tried edit the wp_options table and set siteurl and home to https://mywebsite.com (the same website in the vps has values set to http://mywebsite.com)

AWS Elasticbeanstalk single instance Force SSL Redirect loop htaccess (to force https or to force only http) is simply ignored, I've tried so many solutions but no one worked. The only solution that works for me is a php redirect to http after checking if the server variable http_x_forwarded_server is set

I've read that all the https connections - in eb single instance - through port 443 are "proxied" to port 80 (that could be the problem?)

So, any solutions? I don't want to force https in the website, so I don't want to install plugins that forces https, I just want that the website doesn't broke when navigating the website through https

Upvotes: 0

Views: 945

Answers (1)

peppeocchi
peppeocchi

Reputation: 824

Just after adding the post, I've managed to solve this problem.

For future references, the solutions is to add this variable $_SERVER['HTTPS'] and set it to 'on'.

This is my code

if(isset($_SERVER['HTTP_X_FORWARDED_SERVER'])) {
  $_SERVER['HTTPS'] = 'on';
}

You can add it to index.php, or as I did, in the header.php of your theme (in this case be aware that if you change theme that code will not executed)

Upvotes: 1

Related Questions