IIS中有多个localhost:80个绑定的站点? [英] Multiple localhost:80-bound sites in IIS?
问题描述
(您可以直接跳到问题,但背景是在背景部分。)
(You can skip directly to the question, but the context is on the background section.)
技术背景
- Windows 8
- IIS 7
后台:
和其他几个人一样,我使用IIS并且我不时需要设置本地网站的版本。现在,在设置不同的站点时,为它们分配不同的端口以使它们不重叠是很常见的。因此,您可以将您的站点A设置为端口80,将站点B设置为端口81,依此类推。
As several others, I work with IIS and from time to time I need to set up a local version of a site. Now, in setting up different sites, it is quite common to just assign them different ports so that they don't overlap. So you could have your site A at port 80, your site B at port 81 and so on.
现在,我想设置绑定,以便我能够在端口80下有多个站点,并且标题主机区别我可以同时为这些站点提供有意义的URL。
Now, I want to setup the bindings so that I am able to have several sites under port 80 and with the header host distinction I can at the same time give meaningful URLs to these sites.
执行此操作的选项是添加条目到您的主机文件,例如:
An option to do this is with adding entries to your hosts file, such as:
127.0.0.1 siteA.com
127.0.0.1 siteB.com
通过这种方式,您应该可以浏览到siteA.com或siteB.com并让它在本地运行。
And with this, you should be able to browse to siteA.com or siteB.com and have that working locally.
但是我想多走几步,因为localhost已经设置为匹配127.0.0.1,所以:
But I want to take one more step, as localhost is already set up to match 127.0.0.1, so:
问题:
我已将IIS绑定设置为:
I had set up the IIS bindings as:
site host header port
siteA siteA.localhost 80
siteB siteB.localhost 80
我预计我可以浏览 http://siteA.localhost/ 和 http://siteB.localhost/ 并获取我的网站。
And I expected that I would be able to browse to http://siteA.localhost/ and http://siteB.localhost/ and get my sites.
然而,当我浏览时,似乎我的请求永远不会到达IIS,并且地址未解决。
However, when I browse, it seems that my requests never reach IIS, and the address is not resolved.
为什么不起作用?
更新:
我选择了chue x的答案,因为他解释了为什么这不起作用。对于那些可能遵循相同路径的人,您可能会认为好吧,我可以在hosts文件中添加 *。localhost
,它应该完成。甚至切换到 * .local
或 * .localdev.com
或类似的东西。
I have chosen chue x's answer because he explained why this doesn't work. For those that may follow my same path, you may think "well, I could just add *.localhost
in the hosts file and it should be done." or even switch to *.local
or *.localdev.com
or something of that sort.
然而,这不起作用:中的通配符Windows主机文件
正如chue x指出的那样,我们现在唯一的方法是继续向hosts文件添加条目,或者如何在链接中解释问题,使用另一个DNS服务器。
As chue x pointed out, our only approach right now is to keep adding entries to the hosts file or, how they explain in the linked question, to use another DNS server.
推荐答案
您的主机文件需要与您的IIS绑定匹配,这些绑定必须与网址浏览器匹配。
Your hosts file needs to match your IIS bindings, which have to match the url browser.
因此,如果您的主机文件如下:
So if your hosts file looks like:
127.0.0.1 siteA.localhost
127.0.0.1 siteB.localhost
您的IIS绑定需要:
Your IIS bindings need to be:
site host header port
siteA siteA.localhost 80
siteB siteB.localhost 80
最后,从本地机器上,你需要浏览t o:
Finally, from the local machine, you need to browse to:
http://siteA.localhost
编辑 - 如果您尝试在不添加siteA和siteB的hosts条目的情况下执行上述操作,则无法使用。 DNS无法找到它。例如,如果您尝试浏览到foo.stackoverflow.com会发生什么 - 即使stackoverflow.com是已知地址,请求也会失败。
EDIT - If you are trying to do the above without adding the hosts entries for siteA and siteB, it won't work. DNS won't find it. So for example, what happens if you try to browse to "foo.stackoverflow.com" - the request will fail even though "stackoverflow.com" is a known address.
这篇关于IIS中有多个localhost:80个绑定的站点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!