IIS7 中的通配符子域。 是否有可能让它们像 Apache 中那样?
是否可以配置 IIS7 来实现与 Apache 的通配符域相同的功能? 我对基于 URL 中使用的子域用户在 ASP.NET Web 应用程序中路由用户感兴趣。
这里描述了类似的内容:
http://steinsoft.net/index.php?site =programming/articles/apachewildcarddomain
谢谢
Is this possible to configure IIS7 to achieve the same functionality like Apache has regarding wildcard domains? I'm interested in routing user in ASP.NET web application based on subdomain user used in URL.
Something like is described here:
http://steinsoft.net/index.php?site=programming/articles/apachewildcarddomain
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
答案是否定的,IIS7(仍然)不支持通配符主机名(请参阅 这个)。 如果您想在一个网站上提供多个域服务,目前唯一的解决方法(正如 notandy 所建议的)是使用专用 IP 并通过 DNS 来实现,DNS 确实支持通配符。
2013 更新
为了完整起见,IIS8 还没有此功能。
2016 更新
最后,Windows 2016 中的 IIS 10 支持通配符子域。
The answer is No, IIS7 (still) does not support wildcard hostnames (see this). If you want to serve multiple domain on one website, the only workaround for now, as notandy suggested, is using a dedicated IP and doing it with DNS, which does support wildcards.
2013 Update
For completeness, IIS8 does not yet have this feature either.
2016 Update
Finally, IIS 10 in Windows 2016 supports wildcard subdomains.
答案是是/否。 是的,因为你是
能够将 *.mydomain.com 重定向到一个
网站。 不,因为魔法就在
DNS 而不是 IIS。
操作方法如下:
在 IIS MMC 中,
配置没有主机的网站
标头,然后分配一个 IP 地址
网站。 (如果您有一个 IP 地址
框中,然后您可以跳过此)。
这样,该网站将绑定
特定的 IP 并会监听所有
HTTP 请求发送到 IP,然后您
已完成:)
下一步是确定您的名字
解析适用于通配符
查询并回复正确的IP
地址。 如果您使用 Microsoft DNS
服务,它不允许您创建
a '*' A 记录(假设你已经
在 DNS MMC 中创建了域区域),
您需要执行以下操作:
%windir%\system32\dns\
mydomain.com.dns,用记事本打开它
* A IP.IP.IP.IP
在 DNS MMC 中。
请注意,通过这样做,所有 *
将响应您的IP
较早配置。 例如
abc.mydomain.com、www.mydomain.com、
K2k.mydomain.com 等。
要验证其是否正常工作,请尝试 ping
实用程序
ping(在此插入任何内容).mydomain.com
你应该
从 IP.IP.IP.IP 获取回复
然后尝试浏览,http://(插入
这里的任何内容).mydomain.com/,您
应该得到与您相同的网页
已配置。
来源
The answer is Yes/No. Yes, because you are
able to redirect *.mydomain.com to one
web site. No, because the magic is in
DNS and not IIS.
Here's how you do it:
At IIS MMC,
configure a web site with NO host
header, then assign an IP address to
the site. (if you have one IP address
in the box, then you can skip this).
With this, the web site will bound to
the specific IP and will listen to all
HTTP requests send to the IP, and you
are done :)
Next step is to make sure your name
resolution works for the wildcard
query and reply with the correct IP
address. If you using Microsoft DNS
service, it won't allow you to create
a '*' A record (assuming you already
created the domain zone in DNS MMC),
you need to do the following:
%windir%\system32\dns\
mydomain.com.dns, open it with Notepad
* A IP.IP.IP.IP
in DNS MMC.
Take note that by doing this, all *
will response to the IP that you
configured earlier. E.g.
abc.mydomain.com, www.mydomain.com,
K2k.mydomain.com and etc.
To verify that it is working, try ping
utility
ping (insert anything here).mydomain.com
and you should
get replies from IP.IP.IP.IP
Then try browsing, http:// (insert
anything here).mydomain.com/, you
should get the same web page that you
have configured.
Source
您无法在 Microsoft 的 DNS 中创建通配符 (*) A 记录,但可以创建通配符
CNAME
。 如果您想要做的只是将所有子域定向到特定 IP,那么这将有效。 例如,如果您有www.mydomain.com
的 A 记录,则可以为*.mydomain.com
添加CNAME
记录,并将其指向www.mydomain.com
。 请求标头中的主机名仍然是子域,因此您的 Web 应用程序应该能够捕获它并根据需要进行处理。You cannot create a wildcard (*) A record in Microsoft's DNS, but you can create a wildcard
CNAME
. If all you are trying to do is direct all subdomains to a particular IP, this would work. For example, if you have an A record forwww.mydomain.com
, you could add aCNAME
record for*.mydomain.com
and point that atwww.mydomain.com
. The hostname in the request header will still be the subdomain, so your web app should be able to catch it and handle it if you want.如果您使用 Web 平台安装程序 (http://www.microsoft.com /web/downloads/platform.aspx)并安装“URL重写”模块。 如果您添加“A”记录(如“*.example.com”),则允许将所有子域发送到您的 IIS 服务器。 在 IIS 服务器中,您只需向默认网站添加 URL 重写规则即可执行您想要的任何操作,例如重定向到另一个 URL。 当用户输入“xyz.example.com”时,您可以重定向到“example.com”,并将所有未知子域指向根域。 步骤如下:
安装 Web 平台安装程序:http://www.microsoft.com /web/downloads/platform.aspx
运行它,搜索“URL Rewrite”,然后安装它。
转到默认网站,然后打开“URL 重写”。
点击最右侧的“添加规则”。
命名规则并设置以下内容:
请求的 URL:与模式匹配
使用:正则表达式
模式:(.*)
逻辑分组:全部匹配
添加新条件(单击“添加..”按钮),并设置:
条件输入:{CACHE_URL}
检查输入字符串是否与模式匹配
模式(根据需要修改):(http|https)://(.*?)\.rootdomain\.tld
点击【确定】。
现在向下滚动到操作并设置:
操作类型:重定向
重定向 URL(根据需要修改):{C:1}://rootdomain.tld{R:0}
当您单击“{C:#}”和“{R:#}”旁边的“测试模式”按钮时,“{C:#}”和“{R:#}”来自测试窗口。正则表达式模式条目。 您可以匹配服务器值的一部分并在以后重复使用。
另外,您可能需要查看有关在 URL 中传递 HTTP/HTTPS 的提示(上面步骤 6 中的“{C:1}”):http://weblogs.asp.net/owscott/url-rewrite-protocol-http-https-in-the-action
You can use IIS if you use the Web Platform Installer (http://www.microsoft.com/web/downloads/platform.aspx) and install the "URL Rewrite" module. If you add an "A" record like "*.example.com", this allows all sub-domains to be sent to your IIS server. In the IIS server you simply add a URL rewrite rule to the default website to do whatever you wish, such as redirect to another URL. When a user enters, say, "xyz.example.com", you could redirect to "example.com", and point all unknown subdomains to the root domain. The steps are:
Install Web Platform Installer: http://www.microsoft.com/web/downloads/platform.aspx
Run it, search for "URL Rewrite", and install it.
Go to the default website, and open "URL Rewrite".
Click "Add Rule(s)" on far right side.
Name the rule and set the following:
Requested URL: Matches the Pattern
Using: Regular Expressions
Pattern: (.*)
Logical Grouping: Match All
Add a new condition (click the "Add.." button), and set:
Condition Input: {CACHE_URL}
Check if input string: Matches the Pattern
Pattern (modify as needed): (http|https)://(.*?)\.rootdomain\.tld
Click [OK].
Now scroll down to action and set:
Action Type: Redirect
Redirect URL (modify as needed): {C:1}://rootdomain.tld{R:0}
The "{C:#}" and "{R:#}" come from the test windows when you click the "Test pattern" buttons next to the regex pattern entries. You can match part of a server value and reuse it later.
Also, you may want to checkout this tip on passing on the HTTP/HTTPS in the URL (the "{C:1}" in step 6 above): http://weblogs.asp.net/owscott/url-rewrite-protocol-http-https-in-the-action
更新2:链接已损坏,升级到IIS 10,现在支持通配符。
更新:这工作了一段时间,过了一会儿我就被来自多个请求的轰炸。 我不会推荐这种方法。
确保您的 DNS 记录设置正确(CNAME 记录 *->@),它将完美运行。 使用多个域进行测试。
链接现在已损坏,以前是
http://pzxc.com/apache-style-wildcard- iis 中的主机名重写规则
Update 2: Link is broken, upgrade to IIS 10, it supports wildcards now.
UPDATE: This works for a while, after a while I became bombarded by multiple requests coming through. I would not recommend this method.
Make sure that your DNS records are setup correctly (CNAME record of *->@) and it will work flawlessly. Tested with multiple domains.
Link is broken now used to be
http://pzxc.com/apache-style-wildcard-hostname-rewrite-rules-in-iis
对于无法升级到 IIS 10+ 的用户来说,通过反向代理启用通配符主机名支持并不是很困难。
HTTP 示例如下,其他设置只需几步即可。
在捕获所有站点上创建重写规则以将请求分派到两个站点,
For users who cannot upgrade to IIS 10+, it is not very difficult to enable wildcard host name support via reverse proxy.
The HTTP example is as below, while other setup is just a few more steps.
Create rewrite rules on the catch-all site to dispatch requests to the two sites,