简体   繁体   English

如何在IIS 7上设置子域

[英]How to set up subdomains on IIS 7

I have a website sitting on an IIS 7 server: WWW.example.COM 我有一个位于IIS 7服务器上的网站: WWW.example.COM

I would like to create several sub domains that looks like SUBDOMAIN1.example.COM 我想创建几个看起来像SUBDOMAIN1.example.COM的子域

I created an IIS website and I set the bindings to be http, port 80, the ip address of my server, and SUBDOMAIN1.example.COM and the physical path to a folder under example.COM 我创建了一个IIS网站,我将绑定设置为http,端口80,我的服务器的IP地址,以及SUBDOMAIN1.example.COM和example.COM下文件夹的物理路径

I restarted my website and clicked on browse, the browser than opened with the address: http://SUBDOMAIN1.example.COM 我重新启动了我的网站并点击浏览,浏览器比打开地址:http: //SUBDOMAIN1.example.COM

But the website doesn't show up. 但该网站没有显示出来。

Do I have to do something with the DNS? 我必须对DNS做些什么吗?

This one drove me crazy... basically you need two things: 这个让我疯狂......基本上你需要两件事:

1) Make sure your DNS is setup to point to your subdomain. 1)确保您的DNS设置为指向您的子域。 This means to make sure you have an A Record in the DNS for your subdomain and point to the same IP. 这意味着确保您的子域名在DNS中有A记录并指向相同的IP。

2) You must add an additional website in IIS 7 named subdomain.example.com 2)您必须在IIS 7中添加名为subdomain.example.com的其他网站

  • Sites > Add Website 网站>添加网站
  • Site Name: subdomain.example.com 站点名称:subdomain.example.com
  • Physical Path: select the subdomain directory 物理路径:选择子域目录
  • Binding: same ip as example.com 绑定:与example.com相同的ip
  • Host name: subdomain.example.com 主机名:subdomain.example.com

Wildcard method: Add the following entry into your DNS server and change the domain and IP address accordingly. 通配符方法:将以下条目添加到DNS服务器中,并相应地更改域和IP地址。

*.example.com IN A 1.2.3.4 * .example.com IN A 1.2.3.4

http://www.webmasterworld.com/microsoft_asp_net/3194877.htm http://www.webmasterworld.com/microsoft_asp_net/3194877.htm

If your computer can't find the IP address associated with SUBDOMAIN1.example.COM , it will not find the site. 如果您的计算机找不到与SUBDOMAIN1.example.COM关联的IP地址,则无法找到该站点。

You need to either change your hosts file (so you can at least test things - this will be a local change, only available to yourself), or update DNS so the name will resolve correctly (so the rest of the world can see it). 您需要更改hosts文件 (这样您至少可以测试一些东西 - 这将是本地更改,仅供您自己使用),或更新DNS以便名称将正确解析(因此世界其他地方可以看到它) 。

As DotNetMensch said but you DO NOT need to add another site in IIS as this can also cause further problems and make things more complicated because you then have a website within a website so the file paths, masterpage paths and web.config paths may need changing. 正如DotNetMensch所说,但你不需要在IIS中添加另一个站点,因为这也会导致更多问题并使事情变得更复杂,因为你在网站中有一个网站,所以文件路径,母版页路径和web.config路径可能需要更改。 You just need to edit teh bindings of the existing site and add the new subdomain there. 您只需要编辑现有站点的绑定并在那里添加新的子域。

So: 所以:

  1. Add sub-domain to DNS records. 将子域添加到DNS记录。 My host (RackSpace) uses a web portal to do this so you just log in and go to Network->Domains(DNS)->Actions->Create Zone, and enter your subdomain as mysubdomain.domain.com etc, leave the other settings as default 我的主机(RackSpace)使用门户网站来执行此操作,因此您只需登录并转到网络 - >域名(DNS) - >操作 - >创建区域,然后输入您的子域名作为mysubdomain.domain.com等,留下其他人设置为默认值

  2. Go to your domain in IIS, right-click->Edit Bindings->Add, and add your new subdomain leaving everything else the same eg mysubdomain.domain.com 在IIS中转到您的域,右键单击 - >编辑绑定 - >添加,然后添加新的子域,其他所有内容保持不变,例如mysubdomain.domain.com

You may need to wait 5-10 mins for the DNS records to update but that's all you need. 您可能需要等待5-10分钟才能更新DNS记录,但这就是您所需要的。

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

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