Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does IIS determine what website to hit for localhost

Tags:

iis

iis-6

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?

like image 317
bechbd Avatar asked Dec 08 '22 07:12

bechbd


1 Answers

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.

like image 180
Maladon Avatar answered Feb 12 '23 19:02

Maladon