1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
|
<!doctype html public "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Multi-homed or Virtual Servers on the WN server</title>
<link rev="made" href="mailto:john@math.nwu.edu">
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="last-modified" content="Fri, 09 Oct 1998 18:18:09 GMT">
<meta http-equiv="keywords" content="WN multi-homed or virtual servers">
</head>
<body bgcolor="#FFFFFF">
<p>
<a href="http://hopf.math.nwu.edu/"><img
src="images/powered.jpg"
border="0"
width="190"
height="41"
align="right"
alt="WN home page"
></a>
</p>
<strong>Version 2.0.3</strong>
<br>
<!-- pnuts --> <a href="tilde.html">[Previous]</a> <a href="utility.html">[Next]</a> <a href="manual.html">[Up]</a> <a href="manual.html">[Top]</a> <a href="dosearch.html">[Search]</a> <a href="docindex.html">[Index]</a>
<br clear="right">
<hr size="4">
<!-- #start -->
<h2 align="center">Multi-homed or Virtual Servers on the <em>WN</em>
Server</h2>
<hr size="4">
<p>
Many systems allow multiple IP addresses for a single host. For systems
with this capability it is possible to use a different data hierarchy for
each IP address to which your host responds. Sometimes this is referred
to as "virtual hosts" or a "multi-homed" server since when combined with
<a href="http://www.dns.net/dnsrd/">DNS</a> aliasing it permits a single
server to appear to be multiple servers on different
hosts. Unfortunately, I cannot help you in configuring your system to
respond to multiple IP addresses. (Some information about this can be
found at <a
href="http://www.thesphere.com/%7Edlp/TwoServers/">http://www.thesphere.com/%7Edlp/TwoServers/</a>)
However, if your system supports this capability you can have different
data hierarchies for each IP address if you run the stand-alone version
of the server (<code>wnsd</code>).
</p>
<h3>12.1 <a name="one_server_one_host">One Server per Virtual Host</a></h3>
<p>
There are two ways to have multiple virtual hosts. The easiest is to run
multiple instances of the server each with a different hostname indicated
on the command line via the <a
href="appendixA1.html#h_opt"><code>-h</code></a> option.
</p>
<p>
For example running the commands:
</p>
<blockquote>
<code>
wnsd -h www.abc.com -L abc.log /abc/root
<br>
wnsd -h www.def.com -L def.log /def/root
</code>
</blockquote>
<p>
will 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 UNIX <code><a
href="http://linux-howto.com/man/man3/gethostbyname.3.html">gethostbyname(3)</a></code>
system call for the name supplied on the command line.
</p>
<blockquote>
<em>Note:</em> To use this method make sure the "<code><a
href="configmacros.html#USE_VIRTUAL_HOSTS">#define USE_VIRTUAL_HOSTS</a></code>"
line in <a href="configmacros.html"><code>config.h</code></a> is
commented out.
</blockquote>
<p>
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.
</p>
<h3>12.2 <a name="one_server_many_hosts">A Single Server with Multiple Virtual
Hosts</a></h3>
<p>
The second method to implement a multi-homed server involves only a
single initial instance of the server which responds to all requests and
changes the document root as appropriate based on the IP address or host
name to which the request was sent. To use this method you need to edit
the <a href="configmacros.html"><code>config.h</code></a> file and
uncomment the line containing "<code><a
href="configmacros.html#USE_VIRTUAL_HOSTS">#define USE_VIRTUAL_HOSTS</a></code>".
</p>
<p>
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 <code>wnd</code> with the UNIX <code><a
href="http://linux-howto.com/man/man8/inetd.8.html">inetd(8)</a></code>
system utility. If you use <code>wnsd</code> there is little difference
in efficiency.
</p>
<h4>12.2.1 <a name="one_server_many_hosts.compiled">Compiling in the List
of Virtual Hosts</a></h4>
<p>
To compile in the list of virtual hosts you need to edit the file
<code>wn/vhost.h</code>. This file is quite short and contains something
like:
</p>
<blockquote>
<pre>
#ifdef USE_VIRTUAL_HOSTS
WN_CONST
char *
WN_CONST
vhostlist[][4] =
{
{ "realname.com" , "123.123.121.1", ROOT_DIR, "nickname0" },
{ "virtual1.com" , "123.123.121.1", "/var/data1", "nickname1" },
{ "virtual2.com" , "123.123.121.1", "/var/data2", "nickname2" },
{ "another.ip.com", "123.123.123.2", "/var/data3", "nickname3" },
{ NULL, NULL, NULL, NULL }
};
#endif
</pre>
</blockquote>
<p>
The line containing
<code>{ "virtual1.com", "123.123.121.1", "/var/data1", "nickname1" }</code>,
should be replaced by a line containing one of the IP addresses of your
host instead of <code>"123.123.121.1"</code>, the correct system path to
the corresponding data root instead of <code>"/var/data1"</code>, one of
the hostnames that corresponds to this IP address, and a nickname to use
in logging. The hostname in this line is used by the server in only two
ways: when a redirect header is sent and to pass the correct server host
name to <a href="http://hoohoo.ncsa.uiuc.edu/cgi/">CGI/1.1</a> programs
in the environment variable. The nicknames are used as a field of a <a
href="setup.html#logging">verbose log</a> entry. When using verbose
logging the nickname (enclosed in angle brackets) will be the last field
of each log entry. If the nickname is is empty (i.e. the empty string
<code>""</code> is used) then a number will be used for its value
representing the position of virtual host in the virtual host file.
</p>
<p>
All the 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
<code>{ NULL, NULL, NULL, NULL }</code> line is
unchanged and that you change only the parts inside 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 <a
href="setup.html#installing.configure"><code>configure</code></a> program
or edited the value of "<code><a
href="configmacros.html#ROOT_DIR">#define ROOT_DIR</a></code>" in <a
href="configmacros.html"><code>config.h</code></a>).
</p>
<p>
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 nickname of the virtual host which
received the request. The <a
href="utility.html#wnv2c"><code>wnv2c</code></a> utility can then be used
to produce separate log files for each IP address.
</p>
<h4>12.2.2 <a name="one_server_many_hosts.file">Using a Virtual Hosts List
File</a></h4>
<p>
Instead of compiling in the list of virtual hosts you can keep this list
in a file which will be read each time the server starts. To use this
file you must uncomment the line containing "<code><a
href="configmacros.html#VIRTUAL_HOSTS_FILE">#define VIRTUAL_HOSTS_FILE</a></code>"
in the file <a href="configmacros.html"><code>config.h</code></a> 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
<a href="appendixA1.html#V_opt"><code>-V</code></a> option to the server.
But to turn this feature on, it is necessary that "<code><a
href="configmacros.html#VIRTUAL_HOSTS_FILE">#define VIRTUAL_HOSTS_FILE</a></code>"
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 <code>SIGHUP</code> signal with the UNIX
<code><a
href="http://linux-howto.com/man/man1/kill.1.html">kill(1)</a></code>
utility.
</p>
<p>
The format of this file is one line per virtual host. Each such line
should have the form:
</p>
<blockquote>
<code>
hostname IP_address root_path virtual_host_nickname
</code>
</blockquote>
<p>
with the four parts separated by white space. For example an entry might
be:
</p>
<blockquote>
<code>
myhost.school.edu 111.222.333.444 /usr/local/wn myhost
</code>
</blockquote>
<p>
In particular the hostname should be a fully qualified domain name.
Lines in this file which are empty or start with '<code>#</code>' are
ignored. When using verbose logging the nickname will be enclosed in
angle brackets and used as the last field of each log entry. If the
nickname is omitted a number will be used representing the position of
virtual host in the virtual host file.
</p>
<p>
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
<code>wn/vhost.c</code> and changing the line
"<code>#define MAXVHOSTS (64)</code>". Just replace the
<code>64</code> with the value you wish.
</p>
<p>
<em>WN</em> supports the "<code>Host: </code>" header implemented by
some browsers (e.g. <a
href="http://www.netscape.com/download/prodinfonfs_1.html">Netscape
Communicator</a>) 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 <a
href="http://www.w3c.org/Protocols/">HTTP/1.1</a> protocol requires
browsers to support the "<code>Host: </code>" header.
</p>
<p>
Using this feature requires nothing beyond setting up the server exactly
as described above for virtual 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 "<code>Host: </code>" header (which should contain
the hostname and port it is trying to access) the <em>WN</em> server will
use the root data directory you specified for that host name. Similarly
if a full URL request like
"<code>GET http://host.abc.com/dir/foo.html</code>" is used the
server will use the root data directory corresponding to
"<code>host.abc.com</code>". 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).
</p>
<!-- #end -->
<hr size="4">
<address>
<em>WN</em> version 2.0.3
<br>
Copyright © 1998 <a href="mailto:john@math.nwu.edu">John Franks
<john@math.nwu.edu></a>
<br>
licensed under the <a href="http://www.opencontent.org/opl.html">
OpenContent Public License</a>
<br>
last-modified: Fri, 09 Oct 1998 18:18:09 GMT
</address>
<!-- pnuts --> <a href="tilde.html">[Previous]</a> <a href="utility.html">[Next]</a> <a href="manual.html">[Up]</a> <a href="manual.html">[Top]</a> <a href="dosearch.html">[Search]</a> <a href="docindex.html">[Index]</a>
</body>
</html>
|