简体   繁体   English

将子域重定向到其他服务器上的站点

[英]Redirect subdomain to a site on a different server

I have a site set up on www.mydomain.com. 我在www.mydomain.com上建立了一个网站。 I'm writing a new application that resides on a different computer on my network and want to have my test users to go to test.mydomain.com to access the new site. 我正在编写一个新应用程序,该应用程序位于网络上的另一台计算机上,并且希望让我的测试用户访问test.mydomain.com来访问新站点。 Currently I access the test site by going to a different port at www.mydomain.com:8080. 目前,我通过访问www.mydomain.com:8080上的其他端口来访问测试站点。 How do I configure IIS so that when users go to test.mydomain.com it brings up the new site? 如何配置IIS,以便用户访问test.mydomain.com时可以启动新站点?

I have my DNS set such that www.mydomain.com and test.mydomain.com both go to the old site. 我已将DNS设置为www.mydomain.com和test.mydomain.com都转到旧站点。 I need to tell IIS to use the test server for all the requests that start with test.mydomain.com. 我需要告诉IIS将测试服务器用于所有以test.mydomain.com开头的请求。

I've shared the folder over the internal network and as I had said before port 8080 is open on the firewall and mapped to port 80 on the test server. 我已经在内部网络上共享了该文件夹,就像我在防火墙上打开端口8080并映射到测试服务器上的端口80之前所说的那样。 I've set up a new site in IIS on the production server and have it pointing to the network share and IIS is able to authenticate and see the new site, however when I go to test.mydomain.com it still shows the old page. 我已经在生产服务器上的IIS中建立了一个新站点,并使其指向网络共享,并且IIS可以进行身份​​验证并看到该新站点,但是当我转到test.mydomain.com时,它仍显示旧页面。

Just to level set-- 刚达到水平

  1. You have two ASP.NET applications running on the same machine. 您在同一台计算机上运行两个ASP.NET应用程序。 One is intended to serve content for www.yourdomain.com and the other is meant to serve content for test.yourdomain.com 一种旨在为www.yourdomain.com提供内容,另一种旨在为test.yourdomain.com提供内容

  2. The two ASP.NET application, obviously, live in different folders, and have different IIS application names. 显然,这两个ASP.NET应用程序位于不同的文件夹中,并且具有不同的IIS应用程序名称。 You didn't say what they were, but for the sake of example I shall assume the application names are TestApplication and ProductionApplication, with matching virtual directory names. 您没有说它们是什么,但是为了举例说明,我将假定应用程序名称为TestApplication和ProductionApplication,并具有匹配的虚拟目录名称。

  3. You want all traffic to go to the one box. 您希望所有流量都转到一个框。 If the host that the user typed into the URL is www.yourdomain.com, the request should be handled by ProductionApplication; 如果用户键入URL的主机是www.yourdomain.com,则该请求应由ProductionApplication处理;否则,该请求将由ProductionApplication处理。 otherwise it is handled by TestApplication. 否则由TestApplication处理。

So in terms of routing... 所以就路由而言...

Am I understanding the requirements? 我了解要求吗?

If so, it's easy to do with an IIS redirect rule, which you can set in web.config. 如果是这样,使用IIS重定向规则很容易,您可以在web.config中进行设置。

<rewrite>
    <rules>
        <rule name="AnyName" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^test.yourdomain.com$" />
                <add input="{PATH_INFO}" pattern="^/TestApplication/" negate="true" />
            </conditions>
            <action type="Rewrite" url="\TestApplication\{R:0}" />
        </rule>
    </rules>
</rewrite>

This tells IIS that whenever it receives a request for test.yourdomain.com, it is to modify the URL and insert "TestApplication" before the path that was provided. 这告诉IIS,每当它收到对test.yourdomain.com的请求时,便是修改URL并在提供的路径之前插入“ TestApplication”。

For production you'd do something very similar: 对于生产,您将执行类似的操作:

<rewrite>
    <rules>
        <rule name="AnyName" stopProcessing="true">
            <match url=".*" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^www.yourdomain.com$" />
                <add input="{PATH_INFO}" pattern="^/ProductionApplication/" negate="true" />
            </conditions>
            <action type="Rewrite" url="\ProductionApplication\{R:0}" />
        </rule>
    </rules>
</rewrite>

Detailed instructions can be found on Scott Forsyth's Blog . 有关详细说明,请参见Scott Forsyth的Blog

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM