Creating virtual hosts in IIS

Posted on 2006-11-25
Last Modified: 2013-11-15
I am trying to add virtual hosts to my top level domain name.  For some reason when I do this I get a Bad Request (Invalid Hostname).  Why would I be getting this?
Question by:pingeyeg
  • 3
LVL 23

Accepted Solution

rama_krishna580 earned 500 total points
ID: 18017261

Very often when developing sites it's best to get as close to the production environment setup as possible, so that when you go live the migration to the production server is seamless. One of the required steps is to set up a virtual host on your development web server and configure your machine to see that virtual host. What does this mean? Well essentially instead of typing in a address in my browser I could type and have the browser resolve this request to a dev machine on the internal network, while maintaining the appearance of a fully qualified domain name. Incidently you can use it for a raft of other things, such as creating sub domains. In the following I'll be explaining how to configure virtual hosts IIS 5 running on Windows 2000, setting up your local machine to recognise the virtual host, testing the set up and how I apply this setup to my development.

First things first setting up a virtual host on IIS. There are 2 ways to do this the first is to use the handy wizard, the second by creating a site manually and then modifying its properties. Let's have a look at the wizard first and start off by firing up the IIS MMC (the management console), right click on the computer that represents your server and select new site from the pop up menu. This launches the wizard, click next when you see the splash screen. The first thing you'll need to do si give the site a description (this is the text that appears in the MMC alongside the site you created), in my case I called it "Robbie Slater Dev" as I was setting up the dev environment for the robbie slater web site and then click next.

The next screen is the important one, it's where you set the IP, port and host header information. You can pretty much leave the first two settings as they are (unless your web server listens on a port other than 80 or you want to specify a specific IP address for that site), the host header field is the important one. Since the live web site was called I opted for the internal domain name to look like this www.robbie.shed (it was shorter to type and shed being the name of the dev server). After clicking next you are given the option to supply the full path to the sites root directory, so if you did a default installation and had your site under wwwroot, the path would look something like this: c:\inetpub\wwwroot\robbieslater. Leave the box ticked for anonymous access, unless you want people to provide a username and password to access the site.

The next prompt involves setting access permission If you are using ASP make sure the first two options are ticked. If you use anything else (such as PHP or Cold Fusion) you'll need to make sure the Execute option is ticked (you will also need to add the default document type to be executed, you can read more about this here: How to create IIS mappings for .cfm ). Click next and you are done. Excellent now to the other way of adding virtual hosts.

If you have a site already created, but no host header information set up for it, fear not you can add this information by right clicking on your site and selecting properties. From the dialogue that appears, select the advanced button that appears alongside the IP address drop down. The default entry on the ensuing dialogue should be "IP address (All Unassigned)". Make sure this option is selected and click the Edit... button (if on the other hand you have a specific IP address mapped to this site, then select that option in the dialogue). Another dialogue box pops up, you'll notice a blank Host Header Name field and using the previous example for Robbie's site and would have entered www.robbie.shed in that field. Once you are done click OK until you are all the way through until you are back to your MMC. Stopping and starting your site) at this stage is a good idea.

Now that IIS is configured you are not done yet, your machine won't know that, for example, www.robbie.shed is mapped to an internal IP address, unless of course you are fortunate enough to have a DNS server at your disposal and have added the domain name to the server with the right IP address (might delve a little more into this in a future installment. If not then you will need to edit your hosts file (on win2k machines you should be able to find it here: C:\WINNT\system32\drivers\etc). it usually contains something like this:

# Copyright (c) 1993-1999 Microsoft Corp.
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
# For example:
# # source server
# # x client host localhost

This file allows you to specify an IP address and a hostname for that IP adress. So assuming that your dev server has an IP address of and we have the domain name www.robbie.shed add the following line at the end of the hosts file. www.robbie.shed

Nearly done now... You should not have to, but once you have saved the file, it's safer to reboot your computer at this stage, just to make sure the changes to your host file take effect. Once done, the first test involves attempting to ping the domain name you added. So go to your command prompt and type: ping <your virtual hosts' domain name> . If you were following my example closely (i.e. using robbie.shed) then you would type ping www.robbie.shed. If all is going well the prompt should display a reply with 0% percent packet loss (this can vary depending on your network). Here's the output I received:

c:\>ping www.robbie.shed

Pinging www.sunbeam.cbd [] with 32 bytes of data:
Reply from bytes=32 time<10ms TTL=128
Reply from bytes=32 time<10ms TTL=128
Reply from bytes=32 time<10ms TTL=128
Reply from bytes=32 time<10ms TTL=128

Ping statistics for
  Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
  Minimum = 0ms, Maximum = 0ms, Average = 0ms

If you received something like: Unknown host www.robbie.shed, then something isn't quite right. Check that your hosts has the correct information, or try pinging the IP address of the server to see if it is responding. OK now your machine nows where to look up your virtual domain and now for the acid test, open your browser and enter your virtual domain in the address location. Hopefully your site should be appearing in the browser, but if it doesn't try these things:

Check that the default document you are using has been specified in IIS. For example if you want to use index.php as your default you'll need to specify that in the MMC (right click site, properties and select documents from the dialogue tab, typically you'll find Default.htm and Default.asp in there).
Sometimes the document type you are specifying isn't executed by the application server so have a look here for information on adding document types to IIS: How to create IIS mappings for .cfm
Finally review your virtual host header settings.

LVL 23

Assisted Solution

rama_krishna580 earned 500 total points
ID: 18017264
LVL 23

Expert Comment

ID: 18028526
I understand your point !!! Ok i will make sure from next time !!!

LVL 48

Expert Comment

ID: 18049464
Thanks mate

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is an update and follow-up of my previous article:   Storage 101: common concepts in the IT enterprise storage This time, I expand on more frequently used storage concepts.
A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now