How do I set up a virtual host? That is, I want http://www.foo.com/ to be served off my own machine.
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).
- Name-based virtual host: Multiple hostnames mapped to the same static IP address.
- 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.
- Unix Split Personality: How to Virtual Host
- Linux IP-Alias mini-HOWTO
- Apache Virtual Host documentation
- Does anyone know how to do IP aliasing on Windows?
- How do I use servlet aliasing, so the URL "http://foo.com/mywebapp/servlet/a.b.c.MyServlet" can become "http://foo.com/mywebapp/Thingy"?
- Can I configure Tomcat so that the name of the webapp is not used in the URL? E.g. http://localhost/servlet/HelloWorld, instead of http://localhost/examples/servlet/HelloWorld
- How do I set up virtual hosting on Tomcat in standalone mode?
- How do I set up virtual hosting on Tomcat with Apache?
- How do I set up virtual hosting on Java Web Server?
- How do I set up virtual hosting on Allaire JRun?