raklos
raklos

Reputation: 28555

Elastic Beanstalk redirect http to https for iis site

I am using Elastic Beanstalk on AWS for a .net core site hosted on IIS.

I'm unsure how to get http to redirect to https. Following this:

https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/configuring-https-httpredirect.html

I have done the first step, but unsure what to do in the second step. I'v followed the github link, but dont know what to do with the file.

https://github.com/awsdocs/elastic-beanstalk-samples/blob/master/configuration-files/aws-provided/security-configuration/https-redirect/dotnet/https-redirect-load-balanced-dotnet.config

Instructions are unclear.

I'm open to suggestions of other methods of getting http to redirect to https

Upvotes: 2

Views: 1056

Answers (2)

Mike Gostomski
Mike Gostomski

Reputation: 138

I was confused by all the documentation and answers providing code for rewrite rules, which I could never get to work. I eventually figured out how to do this via the AWS web console:

  1. Make sure you are using an Application Load Balancer for your application's environment.

  2. Add a listener for https, port 443, and your certificate (AWS documentation covers this quite well)

  3. This was the part that took me hours to figure out:
    You cannot configure the redirect from Elastic Beanstalk's load balancer configuration section. You have to go to Services -> EC2 -> Load balancers and then select the load balancer created for your application/environment.
    If you have multiple load balancers, it's hard to determine which one is the correct one. I had to refer to the "Created At" timestamp to know which one to select.

  4. Click the "Listeners" tab

  5. Click the View/edit rules link on the HTTP:80 listener
  6. Click the + icon to add a new rule
  7. Add an action of "Redirect to..." and enter 443 for the port.
    The rest of the inputs defaulted to the correct values.
  8. Add a "Host header" condition and set the value to your host
  9. Save the rule

Upvotes: 5

raklos
raklos

Reputation: 28555

This is what worked for me https://stackoverflow.com/a/47806650/66975

<rewrite>
   <rules>
      <rule name="HTTPS Rule behind AWS Elastic Load Balancer Rule" stopProcessing="true">
         <match url="^(.*)$" ignoreCase="false" />
         <conditions>
            <add input="{HTTP_X_FORWARDED_PROTO}" pattern="^http$" ignoreCase="false" />
         </conditions>
         <action type="Redirect" url="https://{SERVER_NAME}{URL}" redirectType="Found" />
      </rule>
   </rules>
</rewrite>

Upvotes: 0

Related Questions