(You can skip directly to the question, but the context is on the background section.)
Technical Context
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.
IIS supports multiple Web sites on a single server. To create and host multiple Web sites, you must configure a unique identity for each site on the server. To assign a unique identity, distinguish each Web site with at least one of three unique identifiers: an IP address, or a TCP port number or a host header name.
Hosting Multiple Website on IIS using Host HeadersRight-click TestSite and select Edit Bindings. Select the binding you need and click Edit. Specify the unique host name the users will address to, like TestSite, in the Host Name field. Now you can start the second website as well.
The binding '*:80'is assigned to another site. If you assign the same binding to this site, you will only be able to start one of the sites.
If you want to host multiple websites on the same port and IP address, you will have to use a unique Host header. The host header is a part of an HTTP request to the server sent by a client that specifies which website it is addressed to.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With