Another newb question: multiple virtual servers
Hi, I have yet another ignorant question. I have several unrelated web projects that I am working on, and I would like to be able to set up a virtual server for each one for testing purposes, such as: http://project1, http://project2, http://project3. Can someone tell me if this is doable, and if there are any tutorials/resources on this for someone who has 0 experience running a web serer? Sorry for being so ignorant!
[429 byte] By [
severskya] at [2007-11-26 22:16:04]

# 1
Yes, it is doable.
You can setup virtual server either by IP or by name.
If you have one IP, and want to set them up by name (ex. http://project1, http://project2, http://project3) you can do so easily with this type of configuration:
...
<virtual-server>
<name>mydomain</name>
<http-listener-name>http-listener-1</http-listener-name>
<host>*.mydomain.com</host>
<document-root>/www/domain</document-root>
</virtual-server>
<virtual-server>
<name>myotherdomain</name>
<http-listener-name>http-listener-1</http-listener-name>
<host>*.myotherdomain.com</host>
<document-root>/www/myotherdomain</document-root>
</virtual-server>
....
The important part here is that
a) all virtual servers share the same HTTP listener
b) which virtual server serves the request depends on the $HOST request header send by the client. Sun Web Server does the matching for you. It will match $HOST vs. the virtual server's host attribute. Depending on which site you connect to the right virtual server will be used.
c) if the $HOST request header does not match any of the virtual servers, then the default virtual server defined in the HTTP listener will be used.
To create a virtual server, use the Admin GUI, access the configuration, and then add new virtual server. Or use the following CLI command.
wadm> create-virtual-server --config=myconfig --http-listener-name=http-listener-1 --document-root=/www/docs/myserver.com --host-pattern=myserver.com --log-file=../logs/myserver.com-error_logs myserver
Host pattern will be used for matching. Some of this elements might be optional.
Hope that helps. And keep the questions coming :D
Edit: Also check the documentation
[url=http://docs.sun.com/app/docs/doc/819-2629/6n4tgd1s9?a=view] Using Virtual Servers in SJS Web Server 7.0[/url]
# 2
While nsegura's right that Web Server will check the HTTP Host: header to pick a virtual server, I think he omits an important step. Namely, how to tell your web browser that http://project1 refers to your local Web Server install.
Web browsers typically use the Internet Domain Name System (DNS) to resolve a hostname like project1 to an IP address. Since you don't own the project1 domain name (and can't, since all Internet domain names must fall under one of the Top Level Domain such as .com), you need some way to get your web browser to map project1 to your local machine.
On Windows, the easiest way to do this is probably by editing the hosts file. On Windows XP, this is typically C:\WINDOWS\system32\drivers\etc\hosts. You can edit this file with Notepad. The hosts file should already contain a line like the following:127.0.0.1localhostYou can change this to read as follows:127.0.0.1localhostproject1project2project3With this change, all TCP/IP applications, including your web browser, will resolve the hostname project1 to the IP address 127.0.0.1. 127.0.0.1 refers to the local host, i.e. your computer. If your Web Server has an HTTP listener on port 80, you can now use URLs like http://project1 in your web browser.
As an alternative to messing with your hosts file, you could instead create multiple HTTP listeners. For example, you could have one HTTP listener on port 80 and another HTTP listener on port 81. Then, you could create separate virtual servers for these separate HTTP listeners and access them using the URLs http://127.0.0.1 and http://127.0.0.1:81.