tags:

views:

861

answers:

5

I have a development machine setup with IIS 6. I have 3 websites configured on different IP addresses:

Default (All Unassigned) WS1 (192.168.1.250) WS2 (192.168.1.249)

I was wondering how IIS determines which site to hit when I specify localhost in the URL? Is this configurable? If so, how do I go about doing this?

A: 

Isn't one of the sites setup as the default site?

SQLMenace
+1  A: 

localhost is the same as 127.0.0.1 so I assume that would fall under All Unassigned since it doesn't match either of your other IP addresses.

Hardwareguy
+2  A: 

localhost typically means 127.0.0.1, which is a special IP address called the Loopback Address which is always and everywhere defined to mean "the current machine". It is not the same thing as the external IP address of your web server: if IIS is expecting a connection to IP address 192.168.1.250, then a connection to 127.0.0.1 will not match.

localhost is configurable in the Hosts file (typically located at C:\Windows\System32\Drivers\Etc\Hosts). But don't reconfigure it, because if you reconfigure it there are potentially a lot of programs that could break.

Instead, you can set up alternate domains in your Hosts file. For example, you could do

192.168.1.250   my.internal.website.com
192.168.1.249   your.internal.website.org

and then if you browsed to one of those domains, IIS would see the right IP address and show the site you want.

Justice
A: 

"localhost" is mapped to 127.0.0.1 in

C:[your windows directory]\system32\drivers\etc\hosts

There's no extension but hosts is a text file you can edit in your text editor of choice.

John Booty
+3  A: 

When IIS responds to an HTTP request is uses 3 pieces of information to figure out what web site it should use to build the response.

  1. IP address - The browser uses the name in the address bar to perform a DNS query and get the actual IP address of the host. It sends the http request to that IP address.
  2. Port - By default this is 80 for non SSL requests and 443 for SSL.
  3. host header - Part of an http request is a host header. This host header matches the domain name of the address requested by the user, including sub-domain or host names. For example: www.foo.com secure.foo.com server1.foo.com subdomain.foo.com server2.subdomain.foo.com, etc.

Assumptions based on your question:

1 - Your machine has 3 ip addresses assigned:

  • 192.168.1.250 - assigned as web site 1, name WS1
  • 192.168.1.249 - assigned as web stie 2, name WS2
  • both WS1 and WS2 are defined in IIS and mapped to the appropriate IP address

2 - You have a 3rd ip address assigned to your machine that is the original IP address. (This may or may not be the case, I'm assuming it to be so since that's what most folks do when the assign IP's to web sites).

3 - The default web site in IIS has the IP address setting of: (All Unassigned).

4 - You have not specified any host headers or ports in your IIS config.

So, when running a browser on your machine you type: http://localhost (no port number), what does IIS do?

Per previous replies the browser converts localhost to 127.0.0.1 as the IP address and constructs an HTTP request for that IP address. The host header will be localhost.

In this scenario IIS will see that both WS1 and WS2 do not have matching ip addresses and so the default site will be used to process the request.

If you wish to have WS1 or WS2 respond to the request, disable the default site and change the IP address setting to (All Unassigned) for either WS1 or WS2.

Maladon
1,2, 3, and 4 are all correctRight now when I do this it goes to WS2 which is what I find strange. I would have thought it should go to the default website
bechbd
What's in your hosts file?
Maladon