Force Redirect HTTP to HTTPS

For people who use AWS Classic Load Balancer still trying to solve this.

You should read this page: Use Elastic Load Balancing to redirect HTTP traffic to HTTPS | AWS re:Post

Basically, Ngnix should redirect to https if X-Forwarded-Proto: http . This header is set by the load balancer. Thus the communication between web server and load balancer is always http. That means that Ngnix serves only http and the load balancer through https.

So, what I did, was to add the following to my container configuration (web.yml):

run:
    - replace:
       filename: "/etc/nginx/conf.d/discourse.conf"
       from: /server.+{/
       to: |
         server {
           if ($http_x_forwarded_proto = 'http'){
            return 301 https://$host$request_uri;
           }