356 lines
13 KiB
HTML
356 lines
13 KiB
HTML
<!--startcut ==============================================-->
|
|
<!-- *** BEGIN HTML header *** -->
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
<HTML><HEAD>
|
|
<META NAME="generator" CONTENT="lgazmail v1.4G.a">
|
|
<TITLE>The Answer Gang 86: NameVirtualHost in Apache</TITLE>
|
|
</HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
|
|
ALINK="#FF0000">
|
|
<!-- *** END HTML header *** -->
|
|
<!-- begin 2 -->
|
|
<H3 align="left"><img src="../../gx/dennis/qbubble.gif"
|
|
height="50" width="60" alt="(?) " border="0"
|
|
>NameVirtualHost in Apache</H3>
|
|
|
|
|
|
<p><strong>From Rich Price
|
|
</strong></p>
|
|
<p></strong></p>
|
|
|
|
<!-- sig -->
|
|
|
|
|
|
<!-- sig -->
|
|
|
|
|
|
<p align="right"><strong>Answered By Huibert Alblas, Faber Fedor, Mike "Iron" Orr, Heather Stern
|
|
</strong></p>
|
|
<blockQuote>
|
|
I am running <A HREF="http://www.slackware.org/">Slackware</A> 7.1.0 and <A HREF="http://www.apache.org/">Apache</A>/1.3.12 on my web server which I have
|
|
been running for many years. Recently, I acquired a second domain name and
|
|
I attempted to use name based virtual hosting to support both domains on
|
|
this server.
|
|
</blockQuote>
|
|
<blockQuote>
|
|
I have been unable to configure apache to do this. I have been using the
|
|
second edition of "Apache The Definitive Guide" by Ben and Peter Laurie as
|
|
a guide. But repeated attempts to come up with a httpd.conf file have
|
|
resulted in either both web sites showing the same [primary site] pages or
|
|
in both sites showing an error page.
|
|
</blockQuote>
|
|
<blockQuote>
|
|
I have a number of questions that the Laurie's book has not been able to
|
|
answer:
|
|
</blockQuote>
|
|
|
|
<blockQuote><ol>
|
|
<LI>Can you have both a primary site and a "NameVirtualHost" site that use
|
|
<LI>Can you have both a primary site and a "NameVirtualHost" site that use
|
|
the same IP address?
|
|
|
|
|
|
<LI>Should I make both sites be "NameVirtualHost" sites?
|
|
<LI>Should I make both sites be "NameVirtualHost" sites?
|
|
|
|
|
|
<LI>Is there anything obviously wrong with these httpd.conf statements?
|
|
<LI>Is there anything obviously wrong with these httpd.conf statements?
|
|
</ol></blockQuote>
|
|
|
|
<blockquote><pre>#
|
|
NameVirtualHost aaa.bbb.ccc.ddd
|
|
<VirtualHost virt-host-name>
|
|
ServerAdmin relevant-email-address
|
|
DocumentRoot /websites/virthost/htdocs
|
|
ErrorLog /var/log/error_log
|
|
CustomLog /var/log/access_log common
|
|
</VirtualHost>
|
|
#
|
|
</pre></blockquote>
|
|
<blockQuote>
|
|
Any advice would be appreciated!
|
|
</blockQuote>
|
|
<blockQuote>
|
|
Rich Price
|
|
</blockQuote>
|
|
<blockQuote>
|
|
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
|
|
HEIGHT="28" WIDTH="50" BORDER="0"
|
|
> [Halb]
|
|
Yes, as far as I can see you're missing the ServerName entry:
|
|
</blockQuote>
|
|
|
|
<blockquote><pre> <VirtualHost virt-host-name>
|
|
|
|
ServerName virt-host-name
|
|
|
|
ServerAdmin relevant-email-address
|
|
DocumentRoot /websites/virthost/htdocs
|
|
ErrorLog /var/log/error_log
|
|
CustomLog /var/log/access_log common
|
|
</VirtualHost>
|
|
</pre></blockquote>
|
|
<blockQuote>
|
|
Hope it helps
|
|
</blockQuote>
|
|
<P><STRONG>
|
|
<IMG SRC="../../gx/dennis/qbub.gif" ALT="(?)"
|
|
HEIGHT="28" WIDTH="50" BORDER="0"
|
|
>
|
|
Thanks for your reply. But my problem remains.
|
|
</STRONG></P>
|
|
<P><STRONG>
|
|
When I add the NameVirtualHost and <VirtualHost > commands
|
|
[with the ServerName statement] to the end of the httpd.conf file, I
|
|
get the "HTTP 404 - File not found" error message when trying to
|
|
access either website.
|
|
</STRONG></P>
|
|
<blockQuote>
|
|
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
|
|
HEIGHT="28" WIDTH="50" BORDER="0"
|
|
> [Faber]
|
|
Hang on. From what I've seen in this thread, you need to do this:
|
|
</blockQuote>
|
|
|
|
<blockquote><pre>NameVirtualHost aaa.bbb.ccc.ddd
|
|
|
|
<VirtualHost aaa.bbb.ccc.ddd> <-- note this nibbly bit
|
|
ServerName virt-host-name
|
|
<...snip...>
|
|
</VirtualHost>
|
|
</pre></blockquote>
|
|
<blockQuote>
|
|
NOT
|
|
</blockQuote>
|
|
|
|
<blockquote><pre>NameVirtualHost aaa.bbb.ccc.ddd
|
|
|
|
<VirtualHost virt-host-name> <-- this line is the problem
|
|
ServerName virt-host-name
|
|
<...snip...>
|
|
</VirtualHost>
|
|
</pre></blockquote>
|
|
<blockQuote>
|
|
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
|
|
HEIGHT="28" WIDTH="50" BORDER="0"
|
|
> [Iron]
|
|
That's how our sites are set up, those that do name virtual host.
|
|
However, the Apache docs (version 1.3) say you can use either the IP
|
|
or domain name, although they recommend the IP for the NameVirtualHost
|
|
line. I would thus use the IP on both the NameVirtualHost and
|
|
VirtualHost lines so it's easier for the person to match up which
|
|
VirtualHost stanzas go with which NameVirtualHost.
|
|
</blockQuote>
|
|
<blockQuote>
|
|
Note that you can also use ServerAlias to define multiple names for
|
|
one virtual host:
|
|
</blockQuote>
|
|
|
|
<blockquote><pre>NameVirtualHost 10.0.0.1:8080
|
|
<VirtualHost 10.0.0.1:8080>
|
|
ServerName buffy.vampire.slayer
|
|
ServerAlias www.buffy.vampire.slayer
|
|
...
|
|
</VirtualHost>
|
|
</pre></blockquote>
|
|
<blockQuote>
|
|
This can be called the "Rick Moen can't get his users trained not to
|
|
type the 'www'" approach.
|
|
</blockQuote>
|
|
<P><STRONG>
|
|
<IMG SRC="../../gx/dennis/qbub.gif" ALT="(?)"
|
|
HEIGHT="28" WIDTH="50" BORDER="0"
|
|
>
|
|
I figgured it out!!!!
|
|
</STRONG></P>
|
|
<P><STRONG>
|
|
The Apache online documentation says:
|
|
</STRONG></P>
|
|
|
|
<TABLE WIDTH="95%" BORDER="1" BGCOLOR="#FFFFCC"><TR><TD>
|
|
<p align="center">...............</p>
|
|
<P><STRONG><BLOCKQuote>
|
|
Note: the "main server" and any <em> _default</em> servers will never be served for
|
|
a request to a NameVirtualHost IP Address . . .
|
|
</BLOCKQuote></STRONG></P><p align="center">...............</p>
|
|
</TD></TR></TABLE>
|
|
<P><STRONG>
|
|
So I added the origional "main server" as another virtual host like this:
|
|
</STRONG></P>
|
|
<p align="center">See attached <tt><a href="../misc/tag/named-host.httpd.conf">named-host.httpd.conf</a></tt></p>
|
|
<P><STRONG>
|
|
And the original host continued to work with the new httpd.conf file.
|
|
</STRONG></P>
|
|
<P><STRONG>
|
|
The problem with the new host turned out to be a misspelled directory path.
|
|
[I blush with shame].
|
|
</STRONG></P>
|
|
<P><STRONG>
|
|
Thanks for all the help.
|
|
</STRONG></P>
|
|
<P><STRONG>
|
|
Rich Price
|
|
</STRONG></P>
|
|
<blockQuote>
|
|
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
|
|
HEIGHT="28" WIDTH="50" BORDER="0"
|
|
> [Iron]
|
|
Oh, OK. Often you think the problem is one thing but it turns out to be
|
|
something else.
|
|
</blockQuote>
|
|
<blockQuote>
|
|
<IMG SRC="../../gx/dennis/bbub.gif" ALT="(!)"
|
|
HEIGHT="28" WIDTH="50" BORDER="0"
|
|
> [Heather]
|
|
So, I didn't join this thread when it was active during the month, and
|
|
here I am adding this as I edit the thread. But I figured it would be
|
|
valuable to complete the example.
|
|
</blockQuote>
|
|
<blockQuote>
|
|
You need to have permissions for the directory set up in your
|
|
httpd.conf too, since the very default permissions usually explicitly
|
|
describe that anywhere in the web tree should be inaccessible unless
|
|
opened up (or possibly, only open to localhost). The defaults may work
|
|
pretty well until you start moving your web directories to a place
|
|
unplanned for by your installation of Apache. (For example, having a
|
|
websites directory off of the root directory, not exactly
|
|
<a href="http://www.linuxbase.org/">LSB compliant</a>
|
|
, but heck, it's <EM>your</EM> server.) That Rich misspelled this little tidbit,
|
|
then realized and spelled it right, is what fixed him. So here's that
|
|
part, presuming that these are pages for access by a world of visitors,
|
|
not just a limited number of friends.
|
|
</blockQuote>
|
|
<blockQuote>
|
|
AllowOverride suggests what things .htaccess control files can affect.
|
|
</blockQuote>
|
|
<p align="center">See attached <tt><a href="../misc/tag/host-directories.httpd.conf">host-directories.httpd.conf</a></tt></p>
|
|
<blockQuote>
|
|
Now, the fact that he mentions "htdocs" suggests that he probably
|
|
also has a dedicated cgi directory and maybe even a dedicated icons
|
|
directory (so fancy indexing gets a touch of local flavor). So here's
|
|
an expanded and slightly fancier example that covers the lot, and
|
|
puts things in a slightly more reasonable place in the directory tree.
|
|
Also I seperate the logs.
|
|
</blockQuote>
|
|
<p align="center">See attached <tt><a href="../misc/tag/completist.httpd.conf">completist.httpd.conf</a></tt></p>
|
|
<blockQuote>
|
|
Of course, to use my example you should also touch and set
|
|
permissions for the logfiles you'll be keeping, and give them group
|
|
permission that allows the webmasters to see their own stuff.
|
|
</blockQuote>
|
|
<blockQuote>
|
|
You'll want to change that "lettered" IP address to a real one.
|
|
You can use 127.0.0.2 and a bunch of entries in your <TT>/etc/hosts</TT>
|
|
file to test things out if you need to.
|
|
DNS "A records" should exist pointing these sites to your IP
|
|
addrress; it might be good if the less preferred names (the
|
|
ServerAlias values) are all CNAMEs to their primaries, so that at
|
|
least a few browsers will get the hint when bookmarking.
|
|
</blockQuote>
|
|
<p align="center">See attached <tt><a href="../misc/tag/test-fragment.etc-hosts.txt">test-fragment.etc-hosts.txt</a></tt></p>
|
|
<blockQuote>
|
|
Create <TT>/home/websites/virthost1</TT> and its subdirectory <TT>/errors</TT> with 2 files
|
|
in it, likewise for virthost2, and copy their sets of icons in.
|
|
</blockQuote>
|
|
<blockQuote>
|
|
Make sure that the webfiles and grpahics for the web are world readable
|
|
in your filesystem too, so the webdaemon (which usually runs as an
|
|
unprivileged user, either 'nobody' or one dedicated to run only apache)
|
|
can access the files. They can be group writable by the webmaster for
|
|
the given site.
|
|
</blockQuote>
|
|
<blockQuote>
|
|
Keeping the custom error pages in the directory "errors" under the web
|
|
tree and numbered like that is compatible with thttpd; so is the attitude
|
|
that everything under the htdocs directories iw world-readable at the
|
|
filesystem. To really go whole hog with that, your virthostX directories
|
|
would be named the same as the preferred name of the site instead, and your
|
|
thttpd.conf would contain the lines:
|
|
</blockQuote>
|
|
|
|
<blockquote><code><font color="#000033"><br>dir=/home/websites
|
|
<br>vhost
|
|
</font></code></blockquote>
|
|
<blockQuote>
|
|
Useful to know if you're switching over in a hurry if there is some nasty
|
|
apache hole that's been discovered and you can't afford to have the websites
|
|
down while the patch is being prepared. Set symlinks for the
|
|
ServerAliased names and it should just work, though your cgi scripts will be
|
|
dead without additional setup, thttpd doesn't do fancy indices, and the
|
|
logs will be somewhere new.
|
|
</blockQuote>
|
|
<blockQuote>
|
|
Add norobots.txt files for spice if you like to keep your sites
|
|
from being web-indexed until they are ready.
|
|
</blockQuote>
|
|
<p align="center">See attached <tt><a href="../misc/tag/simple.norobots.txt">simple.norobots.txt</a></tt></p>
|
|
<blockQuote>
|
|
When things are good you can take out the second Disallow and replace
|
|
it with lines for specific places that shouldn't be traversed.
|
|
</blockQuote>
|
|
<blockQuote>
|
|
After you've finished mixing all these ingredients in a big mixing
|
|
bowl labelled "disk space", season to taste, stuff in the oven, bake
|
|
at 450 for 10 seconds, frost. Serves thousands.
|
|
</blockQuote>
|
|
|
|
<!-- end 2 -->
|
|
<!-- *** BEGIN copyright *** -->
|
|
<hr>
|
|
<CENTER><SMALL><STRONG>
|
|
<h5>
|
|
<br>Copyright © 2003
|
|
<br>Copying license <A HREF="">http://www.linuxgazette.com/copying.html</A>
|
|
<BR>Published in Issue 86 of <i>Linux Gazette</i>, January 2003</H5>
|
|
</STRONG></SMALL></CENTER>
|
|
<!-- *** END copyright *** -->
|
|
|
|
<SMALL><CENTER><H6 ALIGN="center">HTML script maintained by
|
|
<A HREF="mailto:star@starshine.org">Heather Stern</a> of
|
|
Starshine Technical Services,
|
|
<A HREF="http://www.starshine.org/">http://www.starshine.org/</A>
|
|
</H6></SMALL></CENTER>
|
|
<HR>
|
|
|
|
<!--startcut ======================================================= -->
|
|
<P> <hr>
|
|
<!-- begin tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::-->
|
|
<p align="center">
|
|
<table width="100%" border="0"><tr>
|
|
<td align="right" valign="center"
|
|
><IMG ALT="" SRC="../../gx/navbar/left.jpg"
|
|
WIDTH="14" HEIGHT="45" BORDER="0" ALIGN="middle" border="0"
|
|
><A HREF="../index.html"
|
|
><IMG SRC="../../gx/navbar/toc.jpg" align="middle"
|
|
ALT="[ Table Of Contents ]" border="0"></A
|
|
><A HREF="../lg_answer.html"
|
|
><IMG SRC="../../gx/dennis/answertoc.jpg" align="middle"
|
|
ALT="[ Answer Guy Current Index ]" border="0"></A></td>
|
|
<td align="center" valign="center"><A HREF="../lg_answer.html#greeting"><img align="middle"
|
|
src="../../gx/dennis/smily.gif" alt="greetings" border="0"></A>
|
|
<A HREF="../../tag/bios.html">Meet the Gang</A>
|
|
<A HREF="1.html">1</A>
|
|
<A HREF="2.html">2</A>
|
|
<A HREF="3.html">3</A>
|
|
<A HREF="4.html">4</A>
|
|
</td>
|
|
<td align="left" valign="center"><A HREF="../../tag/kb.html"
|
|
><IMG SRC="../../gx/dennis/answerpast.jpg" align="middle"
|
|
ALT="[ Index of Past Answers ]" border="0"></A
|
|
><IMG ALT="" SRC="../../gx/navbar/right.jpg" align="middle"
|
|
WIDTH="14" HEIGHT="45" BORDER="0"></td></tr></table>
|
|
</p>
|
|
<!-- end tagnav ::::::::::::::::::::::::::::::::::::::::::::::::::::-->
|
|
<!--endcut ========================================================= -->
|
|
<P> <hr>
|
|
<!--startcut ======================================================= -->
|
|
<CENTER>
|
|
<!-- *** BEGIN navbar *** -->
|
|
<!-- *** END navbar *** -->
|
|
</CENTER>
|
|
</p>
|
|
<!--endcut ========================================================= -->
|
|
<!--startcut ======================================================= -->
|
|
</BODY></HTML>
|
|
<!--endcut ========================================================= -->
|