IIS 7 – Setting Up Reverse Proxy Based on Domain Name

domain-name-systemiis-7reverse-proxy

How would I configure IIS 7.0's ARR and URL Rewrite to reverse proxy based on a host.

For example:

http://website1.mydomain.com gets routed internally to internalserver\website1

http://website2.mydomain.com gets routed internally to internalserver2\website2

http://website3.mydomain.com gets routed internally to internalserver2 (default website)

FYI – The public DNS website1.mydomain.com and the rest are all actually pointing to the public IP of mydomain.com.

Note that this is not all the same server. There are multiple web servers INSIDE the firewall and one plain default web server whose port 80 and 443 are exposed to the outside. I have one IP Address and one domain name. Thus, since I have multiple web servers inside my firewall, I need to route hostname subdomains to different web servers on the inside.

Any detailed steps would help tremendously.

Best Answer

Since you're relying on the domain name rather than IP (which is easier in this situation), here's the most straight forward way of doing this:

  • make sure that your outside-facing server has bindings for the 3 sites based on the host header (website1.mydomain.com, etc). You can leave the IP address as (All unassigned). You probably have this done already. -- Basically what I mean is to add a binding to the first site that is "website1.mydomain.com", and to the other two sites in a similar way. Here's a walkthrough on bindings.

  • create 2 Web Farms in ARR on the ARR server. One to internalserver and the other to internalserver2. Use the primary IPs of those servers. You can setup 3 different Web Farms if you want unique health checks for each website. It's ok that two of them point to the same server. -- Steps: Create a new Server Farm called InternalServer and add a single server to it, which is "internalserver". Then create another Server Farm called InternalServer2, and add just "internalserver2" to it.

  • on the last step of the wizard when creating the site, when it asks if you want ARR to create a rule for you, only say 'yes' the first time. Take note of the rule that it creates so that you can learn from it. Then delete it. You want to manage your own rules. -- I'll explain the rules in the next step.
  • you should then set 3 URL Rewrite rules at the global level (IIS Server node, not the website node). URL = .*, use a condition with {HTTP_HOST} for your domain name, and the action should route to the corresponding webfarm. -- Here's an intro to URL rewrite. Follow those steps and enter a rule like the one below:

Example URL Rewrite:

<rule name="site1" patternSyntax="ECMAScript" stopProcessing="true">
  <match url=".*" />
  <conditions logicalGrouping="MatchAll">
    <add input="{HTTP_HOST}" pattern="^website1\.mydomain\.com$" />
  </conditions>
  <action type="Rewrite" url="http://InternalServer1/{R:0}" />
</rule>