I have a domain, let's call it domain.com
.
On my DNS provider, I have configured two sub-domains to point to the same IP address. For example:
sub1.domain.com
=> 185.146.11.17
sub2.domain.com
=> 185.146.11.17
I've got two sites configured in IIS listening on ports 8080 and 8081 respectively.
Now, as traffic is coming through directly on 185.146.11.17:80
, I need to route it to either port 8080
or port 8081
depending on the sub-domain of the request.
I've read about rewrite rules and reverse proxies, but am totally confused as to how to simply achieve what I'm needing based on the sub-domain of the request.
How does one go about this?
After much digging, trial-and-error and pulled out hair, I've managed to solve the problem. It seems in this situation, IIS provides much of the heavy lifting for one and does not actually require any explicit reverse proxy and/or rewrite rules.
With the DNS set as below sub1.domain.com
=> 185.146.11.17
sub2.domain.com
=> 185.146.11.17
All one needs to do is:
1. Stop/remove default website on port 80
.
2. Create new website with:
2.1. Site name set to sub1.domain.com
.
2.2. IP address set to All Unassigned
and port set to 80
.
2.3. Host name set to sub1.domain.com
.
3. Repeat process with sub2.domain.com
.
Following the above steps and it all should magically work. The host names are very important so be sure not to miss those. I would recommend setting this all up for HTTPS and then creating a rule to redirect from HTTP if a request comes in on such a protocol.
Thanks to everyone for providing suggestions.
It sounds like you need to create an ARR load balance to itself.
Prerequisite
1.Application request routing and URL rewrite installed.
2.Three DNS name, one for front-end and two for backend.
3.Three website with domain:
Main Site
SubSite1
SubSite2
4.Create a web farm and add these domain to your web farm.
<globalRules>
<rule name="ARR_MyServer_loadbalance" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<action type="Rewrite" url="http://MyServer/{R:0}" />
<conditions>
<add input="{HTTP_HOST}" pattern="www.candy.com" />
</conditions>
</rule>
</globalRules>
6.Go to configuration manager->web farm and set PreserveHostHeader to false. 7.Go to your web farm->My Server monitoring and managent, ensure all server are healthy Now you are able to load balance for your main site.
Just remember to set HTTP port for each server when you are joining Servers into your web farm.
Applicationhost.config should looks like:
<webFarm name="MyServer" enabled="true">
<server address="domain1.candy.com" enabled="true">
<applicationRequestRouting httpPort="8080" />
</server>
<server address="domain2.candy.com" enabled="true">
<applicationRequestRouting httpPort="8081" />
</server>
<applicationRequestRouting>
<healthCheck url="" />
<protocol preserveHostHeader="false" />
</applicationRequestRouting>
</webFarm>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.