Recently found myself in the position of having to set up an AWS Elastic Load Balancer (ELB) in front of our EC2 instance that is running Windows Server 2012R2. This means the server is running IIS v8.5. Normally this would not be a problem except that we wanted to run SSL on the load balanced site and continue to force non-SSL traffic to use the SSL version.
Normally this is a no-brainer and there are plenty of example URL Rewrites out there on the Interwebs that will handle this but the challenge is if you want Health Checks in ELB to work properly against a REAL LIVE web page. ELB will send a HTTP GET request to any page I wanted on the site. I found numerous example that purported to resolve the problem but none of them seemed to do the job, or they redirected the ELB health check or they just flat out 5xx errored out.
So, in order to resolve this problem I crafted the following workaround:
- Create a site in IIS that does nothing but redirect traffic (permanent or 301) around to the target url. The web.config (only file in the site) is as follows:<?xml version=”1.0″ encoding=”UTF-8″?>
<configuration>
<system.webServer>
<httpRedirect enabled=”true” destination=”https://TARGETSITE.com” exactDestination=”false” />
</system.webServer>
<system.web>
<customErrors mode=”RemoteOnly” redirectMode=”ResponseRewrite”> </customErrors>
</system.web>
</configuration> - Set the bindings for this site to accept only traffic for the following:
- http traffic with a Host Name of www.TARGETSITE.com with a port of 80 and the IP address (the inside/private address) for this server
- http traffic with no Host Name and a port of 88 and the IP address of this server (the inside/private address)
- Ensure that Windows Firewall (if you are using it) will accept TCP traffic on port 88
- Add an exception for port 88 to your Security Group that this server uses, allowing traffic from anywhere
- Configure your ELB instance with the following listeners:
- Configure your ELB instance so that the Health Check uses an HTTP request to port 80 to the page ( /default.aspx ) of your choice.
- Configure bindings on your TARGETSITE.com site in IIS so that it accepts HTTP traffic on port 80.
That should about do it. I’ll assume that you’ve already gotten your SSL certificate installed on your ELB instance
Caveats – Test this out first on a non-live environment as your results may vary. Also, the redirect site is NOT being load balanced at this point so you won’t have any fail over capability unless you set up an ELB just for this purpose. Not a bad idea really…
- Setting up SSL on Amazon Linux Instance under EC2 - July 26, 2018
- Method Chaining of Objects in C# - January 16, 2017
- Native SQL Backup And Restores on AWS RDS - November 9, 2016