1

I currently have an app built on a lightsail server. I used Amazon certificate to create SSL https with a load balancer. Under inbound traffic I have to protocols

Http Enabled
Https Enabled.

When I go to https://app.myexample.com sure enough I get an SSL certificate all good. However I'd like to forward http to https. When you go to http://app.myexample.com you get no secure connection (obviously). How can I force http to go to https?

I was going to do it with an .htaccess file but I read somewhere that it should be done through the Load Balancer. Unfortunately all documentation for this is only for Elastic Beanstalk. I'm using Lightsail. How can I accomplish this on lightsail? enter image description here

FabricioG
  • 167
  • 1
  • 7
  • I've encountered the same situation. Have you been able to find a solution? – Ruslan Dec 13 '20 at 18:44
  • 1
    No I haven't yet @Ruslan – FabricioG Dec 13 '20 at 20:25
  • I have managed to do so only with the the full-blown (non-lightsail) EC2 ELB where listeners are supported https://aws.amazon.com/premiumsupport/knowledge-center/elb-redirect-http-to-https-using-alb/ – Ruslan Dec 24 '20 at 08:24

2 Answers2

1

There is no way to do it on Lighsail services level, but!
AWS load balancer pass http_x_forwarded_proto header further.
It is possible to do redirect on your app, webserver level.
I'm using nginx web server, there this configuration looks like this

server {
    listen 80;
    listen [::]:80;
    location / {
        if ($http_x_forwarded_proto = "http") {
            return 301 https://$server_name$request_uri;
        }
    }
       
}
0

This solution worked for me.

  • This is an instance-level solution, so you should detach all the instances except for one.
  • After all the settings have been updated, make sure to take a snapshot to use it when creating a new instance.
  • This requires some file updates so you may need to use an editor such as Vim.
Chemical Programmer
  • 243
  • 1
  • 4
  • 12