OT:Apache question

Rick Stevens rstevens at vitalstream.com
Sat Feb 21 01:13:31 UTC 2004


Mark Knecht wrote:
> Rick Stevens wrote:
> 
>> Did you hit http://www.knechthome.com/files?  That's how the alias
>> works.
> 
> 
> Rick,
>    Thanks for the info. you're truly generous! I may miss you this 
> afternoon so I'm just zipping this off to say thanks. I haven't tried 
> everything you suggested yet.
> 
>    I'm not sure what I hit. When I'm actually at home, sitting on that 
> machine and I try to do this it tells me something like:
> 
> http://localhost.knechthome.com/files doesn't exist. (
> 
> This is paraphrased a bit.)
> 
> when I'm here at work and I ask for http://marksmusic.myvnc.com/files it 
> (I think my local copy of Mozilla) ends up telling me it cannot find 
> Wizard.knechthome.com. No way it should find it since it's just a 
> machine running Apache behind a remote firewall at my house, but the 
> question I have is why do Apache tell it to look for 
> Wizard.knechthome.com at all? Why doesn't it continue to look for 
> marksmusic,myvnc.com and then ask for the directory called files?
> 
> This is what I need to study this weekend.

Hoo, boy.  Ok.  Read further.

> 
> <SNIP>
> 
>>> The second has an apache2.conf file in which I placed your edits at 
>>> the end:
> 
> 
> Tried moving it but no change yet.
> 
>>
>>
>> Oops!  No, those have to be either before the first "<VirtualHost>
>> </VirtualHost>" clause (to make it server-wide, if you have more than
>> one VirtualHost) or inside the clause (to make it active for JUST this
>> VirtualHost).  For example:
> 
> 
> Great example! I'm going to study that tonight and see if I can make 
> sense of how to put it into my files. The one complication I see is that 
>  the config files are loading other config files, like apache2.conf 
> including commonapache2.conf, so I guess my stuff needs to be before 
> those includes?

No, Apache 2, by default, uses multiple config files that are included
from the main httpd.conf file.  These other files usually are module-
related (e.g. using "ssl.conf" if you're using secure sockets layers and
so on).  The primary config stuff on a per-site basis is still in the
main httpd.conf config file, towards the end.

>> VIRTUAL HOST-SPECIFIC:
>>     <VirtualHost www.knechthome.com>    (or <VirtualHost *>)
>>         Alias /files "/mnt/data/sessions"
> 
> 
> I want to be clear about this point above - the <VirtualHost *> comment 
> above - does this exist by default and then automatically use the name I 
> place in my hosts file??? If it did it could account for why I'm seeing 
> some of this stuff. Something like knechthome.com is in hosts, so a 
> VitualHost gets set up, but then Apache tries to 'resolve' 
> knechthome.com through DNS and cannot, so it bbombs out saying it cannot 
> find it?

"<VirtualHost *>" essentially matches any IP address.  An example is in
order...

If your config contains:

	<VirtualHost www.site1.com>
	    DocumentRoot /usr/sites/site1/www
	</VirtualHost>

	<VirtualHost www.site2.com>
	    DocumentRoot /usr/sites/site2/www
	</VirtualHost>

and "www.site1.com" and "www.site2.com" both resolve the the IP address
on your system, the server will decode the host header and serve the
request based on the appropriate directive (site1 would get pages
from /usr/sites/site1/www, site2 from /usr/sites/site2/www, etc.).  If,
however, you have a third site, "www.site3.com" with the same IP, the
server will NOT respond since there's no directive for site3.com.

The "<VirtualHost *>" directive matches all IPs and domains.  I can't
recall (and it's not obvious from the docs) if the order is significant.
If I remember correctly, a directive layout like this:

	<VirtualHost www.site1.com>
	    DocumentRoot /usr/sites/site1/www
	</VirtualHost>

	<VirtualHost www.site2.com>
	    DocumentRoot /usr/sites/site2/www
	</VirtualHost>

	<VirtualHost *>
	    DocumentRoot /usr/sites/default/www
	</VirtualHost>

would result in site1 and site2 being handled properly, but any other
sites that resolve to your IP would be served from
/usr/sites/default/www (in other words, the "*" acts as a last ditch
match).  However, if "<VirtualHost *>" is the FIRST one, it may be that
ALL sites that resolve to your IP are served from the
/usr/sites/default/www directory ("*" overrides everything).  As I
said, I can't remember.

Be that as it may, if you are going to have just one site on your system
and you really don't care what the URL is, just use the "VirtualHost *"
directive.  That way, if an HTTP packet hits your box, it responds.

> Maybe I'm making it more complicated than it really is.

Not really, but you _said_ you didn't want to be an Apache admin. ;-)

>> I think you'll find that moving your set up will stop that from 
>> happening.  Remember that "Alias" sets up a quasi-symlink (like doing
>> an "ln -s") to something that's not in your "DocumentRoot" directory
>> tree.  The "<Directory>" stuff actually controls the access to the
>> alias' destination (like "chmod" would to the destination of a symlink).
> 
> 
> I hope so, but not yet. Still, I have some serious studying to do I 
> think...
> 
> Also, looking at the commonapache2.conf file it appear I can run a 
> virtual host by possibly having a 'public_html' directory in either my 
> account or a special account I make for only doing Apache?

Hmmm.  That directive doesn't look familiar, and I don't have a
"commonapache2.conf" file on any of my systems that I can refer to.
How did you install apache2, RPM or tarball/build?

>> You still must make sure that Apache can read the directory by doing
>> the chmod stuff.  Apache is running as "nobody" and can't override
>> filesystem permissions.
> 
> 
> Yes, I get that intellectually, now lets see if I can put it into practice.
> 
> Thanks much and have a good weekend.

Okey doke.  I may have time to do a bit of research myself this weekend.
Most of my work is still Apache 1-based.  We don't do a lot of Apache 2
stuff (Apache 2 isn't all that much better than Apache 1, IMHO).
----------------------------------------------------------------------
- Rick Stevens, Senior Systems Engineer     rstevens at vitalstream.com -
- VitalStream, Inc.                       http://www.vitalstream.com -
-                                                                    -
-             To iterate is human, to recurse, divine.               -
----------------------------------------------------------------------





More information about the Redhat-install-list mailing list