Multiple localhost:80-bound sites in IIS?

烈酒焚心 提交于 2019-12-09 08:41:05

问题


(You can skip directly to the question, but the context is on the background section.)

Technical Context

  • Windows 8
  • IIS 7

Background:

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.

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

And with this, you should be able to browse to siteA.com or siteB.com and have that working locally.

But I want to take one more step, as localhost is already set up to match 127.0.0.1, so:

Question:

I had set up the IIS bindings as:

site    host header       port
siteA   siteA.localhost   80
siteB   siteB.localhost   80

And I expected that I would be able to browse to http://siteA.localhost/ and http://siteB.localhost/ and get my sites.

However, when I browse, it seems that my requests never reach IIS, and the address is not resolved.

Why isn't that working?


Update:

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.

That, however, doesn't work: Wildcards in a Windows hosts file

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.


回答1:


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

Your IIS bindings need to be:

site    host header       port
siteA   siteA.localhost   80
siteB   siteB.localhost   80

Finally, from the local machine, you need to browse to:

http://siteA.localhost

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.



来源:https://stackoverflow.com/questions/16839268/multiple-localhost80-bound-sites-in-iis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!