title: Cloudflare repeated redirects error (Node JS app, NGINX for reverse proxy, Amazon EC2, SSL)
body: <p>I have a node application running on Amazon EC2 server on port 3000 and NGINX reverse proxy running on the same server instance and Cloudflare is my DNS. 
  I am trying to attach domain name with the node application via both port 80(http) and port 443(https)</p>
  
  <p>In Nginx config file if I listen on port 80 everything works fine.
  Following is the config file(No problem with this as I am listening on port 80):</p>
  
  <pre><code>server {
      listen 80;
  
      server_name example.in;
      location / {
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_set_header  Host       $http_host;
        proxy_pass        http://127.0.0.1:3000;
      }
  }
  </code></pre>
  
  <p>But if try to listen on 443 I am getting ERR_TOO_MANY_REDIRECTS.</p>
  
  <p>This is the config file: (I am using Cloudflare provided private and public key)</p>
  
  <pre><code>server {
      listen 80;
      return 301 https://$host$request_uri;
  }
  
  
  server {
  
      listen 443;
      server_name example.in;
  
      ssl_certificate           /etc/nginx/certs/cloudflare.pem;
      ssl_certificate_key       /etc/nginx/certs/cloudflare.key;
  
      ssl on;
      ssl_session_cache  builtin:1000  shared:SSL:10m;
      ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
      ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
      ssl_prefer_server_ciphers on;
  
      access_log            /var/log/nginx/nginx.vhost.access.log;
  
      location / {
  
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto $scheme;
  
        proxy_pass          http://localhost:3000;
        proxy_read_timeout  90;
  
        proxy_redirect      http://localhost:3000 https://example.in;
      }
    }
  </code></pre>
  
  <p>I followed this <a href="https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-with-ssl-as-a-reverse-proxy-for-jenkins" rel="nofollow noreferrer">link</a>
  I am very new to Nginx and Cloudflare. I don't know where I am messing it up. Thanks for helping out</p>