For example running the commands
swn -h www.abc.com -L abc.log /abc/rootwill start two instances of the server, both on the same port (80) but responding to different IP addresses. The server will ascertain the appropriate IP address by using the gethostbyname() system call for the name supplied on the command line. Note: To use this method make sure the #define USE_VIRTUAL_HOSTS line in config.h is commented out.
swn -h www.def.com -L def.log /def/root
This method has the disadvantage of using somewhat more resources than the alternate method (described below) because at least one instance of the server for each host name is running at all times and thus using memory. On the other hand with this method it is possible to specify a different log file for each host, while the method below uses only one log file and a utility to separate it into the contributions of each host.
#define USE_VIRTUAL_HOSTS
Then you have two choices. You can either create a file containing a list of the virtual hosts or you can build this list into the compiled version of the sever by editing one of the source files and recompiling. If you have only a few virtual hosts and you don't anticipate adding new ones, I recommend compiling in the list. This is easy to do and much more efficient if you use wn with inetd. If you use swn there is little difference in efficiency.
#ifdef USE_VIRTUAL_HOSTS WN_CONST char * WN_CONST vhostlist[][3] = { { "realname.com" , "123.123.121.1", ROOT_DIR }, { "virtual1.com" , "123.123.121.1", "/usr/local/data1" }, { "virtual2.com" , "123.123.121.1", "/usr/local/data2" }, { "another.ip.com", "123.123.123.2", "/usr/local/data3" }, { NULL, NULL, NULL } }; #endif
The line containing { "virtual1.com", "123.123.121.1", "/usr/local/data1" }, should be replaced by a line containing one of the IP addresses of your host instead of " 123.123.121.1", the correct system path to the corresponding data root instead of "/usr/local/data1" and the hostname that corresponds to this IP address. This hostname is used by the server in only two ways: when a redirect header is sent and to pass the correct server name to CGI scripts in the environment variable.
The other lines of this file should be changed in a similar fashion. You may have more as many lines as you wish and you should remove any of the lines you don't need. Don't change anything else. In particular make sure that the { NULL, NULL, NULL} line is unchanged and that you change only the parts in quotation marks. If the IP address by which the server is accessed does not match any of the addresses listed in this file then the server will use the default data root (as specified when you ran the "configure" script or edited the value of ROOT_DIR in config.h).
The server will not produce separate log files for each IP address. However, if the server is configured to produce verbose logs then each entry is tagged at the end with the IP address which received the request. The utility v2c can then be used to produce separate log files for each IP address.
#define VIRTUAL_HOSTS_FILE "/usr/local/wn/virtual_hosts"in the file config.h and change the quoted path to the full path of a file containing virtual host information in a format described below. Then you must recompile the server. Once this has been done you may change the file you use with the -V option to the server. But to turn this feature on, it is necessary that this #define be uncommented when the server is compiled. Each time this file is changed, in order for the change to take effect, you will need to restart the server or send it the SIGHUP signal with the "kill -HUP
The format of this file is one line per virtual host. Each such line should have the form
hostname IP_address root_pathwith the three parts separated by white space. For example an entry might be
myhost.school.edu 111.222.333.444 /usr/local/wnIn particular the hostname should be a fully qualified domain name. Lines in this file which are empty or start with '#' are ignored. By default there is a maximum of 64 virtual hosts allowed in a virtual host file. But this can be increased by editing the file wn/vhost.c and changing the line "#define MAXVHOSTS (64)". Just replace the 64 with the value you wish.
WN now supports the "Host: " header implemented by some browsers (e.g. Netscape2.x) and so-called "full URL requests". For browsers that support either of these features it is now possible to have multiple virtual hosts with a single IP address. The HTTP/1.1 protocol will require browsers to support the Host: header.
Using this feature requires nothing beyond setting up the server exactly as described above for vitual hosts. Of course, all your virtual hosts will have the same IP number if your system only has one. Then if a browser provides the Host: header (which should contain the hostname and port it is trying to access) the WN server will use the root data directory you specified for that host name. Similarly if a full URL request like "GET http://host.abc.com/dir/foo.html" is used the server will use the root data directory corresponding to "host.abc.com". If the browser provides neither of these the server will use the first root data directory whose IP number matches (which will be the first in your list if you have only one IP address).