Elastic Beanstalk Http Redirect to Https
<p>I know this question has been asked before, but nothing seems to be working for me. I've tried multiple different things, such as the answers described in these questions:</p>

<p><a href="https://stackoverflow.com/questions/24297375/how-to-get-elastic-beanstalk-nginx-backed-proxy-server-to-auto-redirect-from-htt">How to get Elastic Beanstalk nginx-backed proxy server to auto-redirect from HTTP to HTTPS?</a>
<a href="https://stackoverflow.com/questions/24603620/redirecting-ec2-elb-from-http-to-https">Redirecting EC2 elb from http to https</a></p>

<p>None of them seem to work. I'm an aws noob, so I'm not entirely sure how editing config files works - or if I've done something wrong.</p>

<p>My setup is the following:</p>

<ul>
<li>Route 53 points to Elastic Beanstalk (nginx)</li>
<li><a href="https://i.stack.imgur.com/5LVqJ.png" rel="noreferrer">ELB port configuration with ACM certificate</a> (using tcp/ssl as it makes my websockets work)</li>
<li>nodejs app on port 8080</li>
</ul>

<p>My current nginx.config file in my .ebextensions folder (got this from <a href="http://www.finik.net/2014/10/29/Beanstalk/" rel="noreferrer">this article</a>):</p>

<pre><code>files:
  "/tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf" :
    mode: "000755"
    owner: root
    group: root
    content: |
        upstream nodejs {
            server 127.0.0.1:8081;
            keepalive 256;
        }
        server {
            listen 8080;
            set $fixedWWW '';
            set $needRedir 0;
            # nginx does not allow nested if statements
            # check and decide on adding www prefix
            if ($host !~* ^www(.*)) {
                set $fixedWWW 'www.';
                set $needRedir 1;
            }
            # what about that https? the traffic is all http right now
            # but elastic load balancer tells us about the original scheme
            # using $http_x_forwarded_proto variable
            if ($http_x_forwarded_proto != 'https') {
                set $needRedir 1;
            }
            # ok, so whats the verdict, do we need to redirect?
            if ($needRedir = 1) {
                rewrite ^(.*) https://$fixedWWW$host$1 redirect;
            }
            location / {
                proxy_pass  http://nodejs;
                proxy_set_header   Connection "";
                proxy_http_version 1.1;
                proxy_set_header        Host            $host;
                proxy_set_header        X-Real-IP       $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
            }
            gzip on;
        }
</code></pre>

<p>But this doesn't seem to do anything. I've run out of ideas. I'm not sure whether I'm missing a step or something but I don't know what to do. As a workaround I've got my angularjs front end redirecting non-https requests, but this is too hacky and some of the DOM renders before the redirect, I'd like to redirect at the load balancer - where it should redirect.</p>