Examples of name-based virtual hosting
In this example, we'll set up name-based virtual hosting in our Tomcat installation.
As a first step, edit your hosts
file to add the following lines. You may need to ensure that your user account has the appropriate privileges to edit this file.
127.0.0.1 www.localswengsol.com 127.0.0.1 localswengsol.com 127.0.0.1 www.localswengsol-2.com
This ensures that when you type in one of these domain names, your DNS resolver will return the same IP address, in this case, the loopback address for your local host.
Start up your Tomcat server, and navigate to either http://localswengsol.com:8080/devguide
or http://www.localswengsol.com:8080/devguide
. Both URLs should now take you to our familiar devguide
web application's index page. Remember that you can also get here using the original URL, http://localhost:8080/devguide
.
However, this only works on Tomcat because all the requests received by our Engine
are simply being forwarded to the default virtual host named...