windows IIS7中不同的域到不同的页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/494822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:54:24  来源:igfitidea点击:

Different domains to different pages in IIS7

windowsconfigurationiis-7hostingdns

提问by Germstorm

I have a Default Web Siteand another web application (let's call it Application2) inside the Default Web Site in IIS7.

我在 IIS7 的默认网站中有一个默认网站和另一个 Web 应用程序(我们称之为Application2)。

I have 2 registered domain names, let's say www.example.comand www.example.net.

我有 2 个注册域名,比如说www.example.comwww.example.net

I would like to configure things that when I open www.example.comI get Default Web Site, when I open www.example.netI get Default Web Site/Application2.

我想配置一些东西,当我打开www.example.com 时我得到Default Web Site,当我打开www.example.net 时我得到Default Web Site/Application2

www.example.com -> Default Web Site
www.example.net -> Default Web Site/Application2

How can I do that?

我怎样才能做到这一点?

采纳答案by Codex73

First you need to decide if your going to use Name Based or IP Based hosting.

首先,您需要决定是使用基于名称的主机还是基于 IP 的主机。

IP-Based uses unique ip's to determine which virtual host it will serve and Name Based will actually use the host header which is sent by your client browser.

IP-Based 使用唯一的 ip 来确定它将服务哪个虚拟主机,而 Name Based 将实际使用由您的客户端浏览器发送的主机标头。

So let's see two scenarios:

那么让我们看两个场景:

Scenario # 1 (ONE IP TO SHARE)

场景 #1(一个 IP 共享)

You have a server with only one IP, could be either private or public as long as the domains you are serving are properly configured in the dns serving you internally or your client externally (NAT).

您的服务器只有一个 IP,可以是私有的或公共的,只要您服务的域在为您提供内部服务或外部客户端 (NAT) 的 dns 中正确配置。

I suggest that for the sake of this tutorial you stop the default website. Ok.

为了本教程,我建议您停止默认网站。好的。

You will set up one site in II7 and name it accordingly. Go to the right hand side of the manager and look for "Bindings" under actions menu; making sure you have the new site selected on your left pane. Now under "Site Bindings" select the ip address you will be sharing between the sites (name based hosting). Under "Hostname" enter domain # 1 "www.example.com", hit ok.

您将在 II7 中设置一个站点并对其进行相应命名。转到管理器的右侧,在操作菜单下查找“绑定”;确保在左侧窗格中选择了新站点。现在在“站点绑定”下选择您将在站点之间共享的 IP 地址(基于名称的托管)。在“主机名”下输入域#1“www.example.com”,点击确定。

Follow the same procedure above with the other domain or domains, making sure they have diferent hostnames and same ip's.

对其他域执行上述相同的过程,确保它们具有不同的主机名和相同的 ip。

That's it. You will now be able to start those sites and run them at the same time.

就是这样。您现在可以启动这些站点并同时运行它们。

The same principle above applies if your using the "Default Site". "Default Site" is just a name MS gave the default created one.

如果您使用“默认站点”,则上述原则同样适用。“默认站点”只是 MS 为默认创建的站点命名的名称。

Scenario # 2 (MULTIPLE IP TO SHARE)

场景 #2(多个 IP 共享)

If you have either some private or public ip to spare, or at least until you do the exercise the only diference here is that sites you will set up and don't have to specify the "Hostname" per each site, as this is basically done in the DNS zones itself. The sites will respond for any request made to those ip's on port 80 regardless.

如果您有一些私有或公共 ip 可用,或者至少在您进行练习之前,唯一的区别是您将设置的站点并且不必为每个站点指定“主机名”,因为这基本上是在 DNS 区域本身中完成。无论如何,这些站点都会响应对端口 80 上这些 ip 的任何请求。

When will you need to use multiple Ip's to serve websites. Well it all depends.

您什么时候需要使用多个 Ip 来为网站提供服务。嗯,这一切都取决于。

Some reasons are: Network Isolation (Security), Applications which don't work well under name based hosting, SSL Certificates Bindings 443(PRE II7), and mostly complete control over site. There are of course more reasons, but I'll let others write a bit also.

一些原因是:网络隔离(安全性)、在基于名称的托管下无法正常工作的应用程序、SSL 证书绑定 443(PRE II7),以及对站点的完全控制。当然还有更多的原因,但我也会让其他人写一点。

Have fun.

玩得开心。

回答by DavGarcia

Edit... upon further investigation I found that if you can set up multiple sites and run them simultaneously. Just need to stop and start the sites after setting the host values to get them to both run at the same time.

编辑...经过进一步调查,我发现如果您可以设置多个站点并同时运行它们。只需要在设置主机值后停止和启动站点即可让它们同时运行。

Original post:

原帖:

The straight-forward way to do this would be to add another application by opening IIS and right-clicking Sites then select Add Web Site. In there you can specify the physical path of Application2 and also set the "host" to "www.example.net" which will filter all those requests to your second site. Any requests that don't match "www.example.net" will still go to the default web site.

执行此操作的直接方法是通过打开 IIS 并右键单击“站点”然后选择“添加网站”来添加另一个应用程序。在那里您可以指定 Application2 的物理路径,并将“主机”设置为“www.example.net”,这将过滤到您的第二个站点的所有这些请求。任何与“www.example.net”不匹配的请求仍将转到默认网站。

That approach will work fine on Windows Server using IIS, but on Vista's IIS7 it won't work since you can only have one site running at a time. To start the second site, you'd first have to stop Default Web Site.

这种方法在使用 IIS 的 Windows Server 上可以正常工作,但在 Vista 的 IIS7 上它不起作用,因为您一次只能运行一个站点。要启动第二个站点,您首先必须停止默认网站。