title: .net Core - HTTPS with AWS Load Balancer and Elastic Beanstalk doesn't work
body: <p>I have a website that runs HTTPS correctly in my local environment.  When I upload it to AWS it just times out or redirects forever.</p>
  <p>My setup in AWS is an Elastic Beanstalk application, an RDS database running MS SQL, I added a Load Balancer to forward the HTTPS requests, and I have a SSL certificate properly assigned to the Load Balancer.  From all I can tell my app is running, in fact, Entity Framework fired off and correctly built my database in my RDS instance.  I just can't reach the website through the internet.</p>
  <p>I've tried setting the Listeners different ways.  If I set them like this, it just redirects forever:
  <a href="https://i.stack.imgur.com/nbOYU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nbOYU.png" alt="Redirect Forever" /></a></p>
  <p>If I set them like this, it just times out:
  <a href="https://i.stack.imgur.com/5sLyP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5sLyP.png" alt="enter image description here" /></a></p>
  <p>I have the <a href="https://docs.microsoft.com/en-us/aspnet/core/security/enforcing-ssl" rel="nofollow noreferrer">default HTTP/HTTPS port forwarding code in my Startup.cs</a>:</p>
  <pre class="lang-cs prettyprint-override"><code>public void ConfigureServices(IServiceCollection services)
  {
      // Sets all calls to require HTTPS: https://docs.microsoft.com/en-us/aspnet/core/security/enforcing-ssl
      services.Configure&lt;MvcOptions&gt;(options =&gt;
      {
          options.Filters.Add(new RequireHttpsAttribute());
      });
      ...
  }
  
  public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
  {
      // Force all HTTP requests to redirect to HTTPS: https://docs.microsoft.com/en-us/aspnet/core/security/enforcing-ssl
      var options = new RewriteOptions().AddRedirectToHttps();
      app.UseRewriter(options);
  
      ...
  
      app.UseForwardedHeaders(new ForwardedHeadersOptions
      {
          ForwardedHeaders = ForwardedHeaders.XForwardedFor |
                              ForwardedHeaders.XForwardedProto
      });
      ...
  }
  </code></pre>
  <p>I've spent days on this and I can't get it to work.  I've tried taking all of my HTTPS code out and that doesn't work.  I've tried code solutions from blogs like <a href="http://blog.treeloop.com/asp-net-core-url-rewrite-module-behind-load-balancer/" rel="nofollow noreferrer">this</a> and <a href="https://blogs.msdn.microsoft.com/gabeshapiro/2017/08/14/redirect-http-to-https-when-using-asp-net-core-in-web-app-on-linux-azure-app-service/" rel="nofollow noreferrer">this</a> and that doesn't work either.  From what I've read, the Load Balancer ends up handling the HTTPS request and then forwards an HTTP request to my app.  But I don't know how to properly handle that, still enforce HTTPS, and redirect HTTP to HTTPS.</p>
  <p>This seems like it would be something that would just work out of the box without a bunch of setup from me.  If it's not, I would think a lot of other people would have run into this problem by now and there'd be info about it on the internet.  Am I missing something small?  Because I'm totally at my wit's end about it.</p>
  <p>If you can answer this, you'll be my new hero.</p>