How do I set up a virtual host? That is, I want http://www.foo.com/ to be served off my own machine.

Alex Chaffee

First off, if www.foo.com is going to be the only hostname served off your machine, then it's not technically a virtual host. Virtual hosting is when you want multiple hostnames to be served off the same machine. If there's only one hostname, then it's an "actual" host :-)

In any case, you need to contact your ISP and ask them to set up a DNS mapping from www.foo.com to your machine's static IP address, and configure your machine and/or web server so it thinks "www.foo.com" is its own name. Technical details of this process are outside the scope of this FAQ (though if someone wants to submit a feedback with a pointer to instructions, please do).

There are two techniques for true virtual hosting. (Both require the involvement of your DNS ISP, as above.)

  1. Name-based virtual host: Multiple hostnames mapped to the same static IP address.
  2. IP-based virtual host: Multple hostnames, each mapped to a different static IP address, but one machine responding to all of those multiple IP addresses. These are often called "IP aliases" or "multiple interfaces" (here "interface" refers to the TCP/IP interface, not any of the other infinite definitions of "interface").

See the references below for more information on enabling IP aliasing for your OS.

From this point, configuration details vary widely based on your operating system, your web server, and your servlet engine. We will defer answering them here; instead, we request specific FAQ questions on each combination of web server and servlet engine.

If your servlet engine supports the Servlet spec 2.2 or greater, you will probably need to re-map the "default context", so "/" maps to "/mywebapp/". See this FAQ for doing this on Tomcat.

See also: