Run two web sites on same port on IIS 7.5?
Asked Answered
E

2

13

We need to be able to run two versions of one ASP.net web application on the same intranet server and port number, but with one mapped to / and the other mapped to /experimental (not real names, but close enough).

C:\inetpub\wwwroot\Version1 => http://test1.organization.com/ C:\inetpub\wwwroot\Version2 => http://test1.organization.com/experimental

The first URL has already been exposed to some beta users and therefore needs to be kept somewhat stable. The second will contain experimental code that only users going to /experimental will see. We don't have the option of using a different server or a different port.

I've achieved this in the past by having / mapped to a site under Sites in IIS, then adding the second site as an application underneath it, and aliasing it to /site2.

Server Sites Default Web Site <= physical path mapped to first version and / / Application1 <= nested application mapped to second version and /experimental

However, this seems sloppy. Would it be cleaner to do this with a rewrite rule or with ARR? If so, how?

Estrella answered 17/8, 2011 at 1:51 Comment(1)
The nested approach you have already tried is the only sensible way I know to acheive this. You can't anyway define a web site that is mapped to test1.organization.com/experimental because the site is defined as everything before the first /. The first part after the first / is either an application, or a subdirectory under the root application.Tintoretto
E
13

A combination of ARR and rewrite rules will solve this nicely. Here are the steps to follow:

  1. Download and install ARR http://www.iis.net/download/ApplicationRequestRouting
  2. In IIS Manager, select your machine in the Connections pane, double-click the Application Request Routing feature in the IIS section, click on the "Server Proxy" link in the Actions pane, then check the "Enable proxy" checkbox and choos the Apply action.
  3. Change the bindings of your two existing websites, for instance, bind the Released website to port 81, and the Experimental website to port 82.
  4. Create a new website and app pool, and bind it to http:*:80:. Name it "Default Web Site". Point its physical path to "%SystemDrive%\inetpub\DefaultWebSite"
  5. Create a web.config file for the "Default" website, and write your routing rules there:

    <rules>
        <rule name="Reverse Proxy for Experimental" stopProcessing="true">
            <match url="^.*/experimental/.*" />
            <action type="Rewrite" url="http://{HTTP_HOST}:82/{R:0}" />
        </rule>
        <rule name="Reverse Proxy for Release" stopProcessing="true">
            <match url=".*" />
            <action type="Rewrite" url="http://{HTTP_HOST}:81/{R:0}" />
        </rule>
    </rules>
    
  6. You may have to fiddle somewhat with your rewrite rules, you can experiment using the URL Rewrite Module applet on IIS, and read more about it here: http://learn.iis.net/page.aspx/500/testing-rewrite-rule-patterns/ For further help be sure and browse Ruslan Yakushev's blog: http://ruslany.net/

This will give you three completely separate websites, accessibly through a single facade on port 80 (though of course you can hit each website directly on port 81 and 82 if you need to: http://localhost:81/default.aspx, for example).

Escarole answered 17/8, 2011 at 5:31 Comment(3)
Thanks for responding. Just to confirm: In this scenario, if I bind site1 to 80, site2 to 81, and site3 to 82, I should be able to route all requests for site1/default.aspx to site2/default.aspx, and all requests for site1/test/default.aspx to site3/default.aspx?Estrella
@Geoffrey McGrath Thanks for your detail instruction. However I could not make it. My rules are - <rule name="Reverse Proxy for Test" stopProcessing="true"> <match url="^.*/test/.*" /> <action type="Rewrite" url="http://{HTTP_HOST}:9090/{R:0}" /> </rule> <rule name="Reverse Proxy for Release" stopProcessing="true"> <match url=".*" /> <action type="Rewrite" url="http://{HTTP_HOST}:81/{R:0}" /> </rule> . Port 9090 rule has never been rewritten. When I type in mywebsite/test, it always brings me to mywebsite:81/test.Aswarm
Don, for the rule you've written, your test URL must include a trailing slash, and optionally additional data following the trailing slash. These two examples should work for you: (1) mywebsite/test (2) mywebsite/test/myfile.htmEscarole
K
3

Can you run one of the sites at a different subdomain, say test1.organization.com and beta1.organization.com? If so then you can set them both up as top-level websites in IIS and set the Host Name on each Site Binding so they can both run on the same IP address and port.

Kai answered 17/8, 2011 at 2:10 Comment(5)
Thanks for responding. No, we cannot do that. The DNS folks are not going to let us register a new subdomain for a temporary hosting situation like ours. My thought was to do the default (one top level site, one nested application) or one top level site with two virtual directories or nested applications and some kind of routing.Estrella
That's too bad. Especially since you don't have to register a subdomain, just have someone add a DNS entry (in other words it's free). =]Kai
Seriously though, if you use the nested approach, one thing to watch out for is that the nested application will inherit web.config settings from the parent unless you disable it (see here for more info: #367782). That's one of the reasons why I like to avoid nesting apps like that.Kai
Sorry, I should have used a lighter term than register. In the past, that used to be a phone call to someone; now it requires change control meetings and sign-offs. The only thing we have control over is the the web servers themselves.Estrella
Yep, I know how it is. Probably 40 hours worth of meetings for a change that literally takes 15 seconds to make. In light of that, it certainly makes sense to try a different approach.Kai

© 2022 - 2024 — McMap. All rights reserved.