Apache Help

Lucas Peet lpeet at eccod.com
Fri Mar 1 17:51:18 CST 2002


...I hate to do this, and I don't want this to turn into some petty
"who's right, who's wrong" thread, but I believe Bob *is* right on the
<VirtualHost *> directive.  I just finished configuring my server a few
weeks ago, and had to figure this one out too.  When I tried to put the
server name in the VirtualHost directive:

### Begin httpd.conf ###

NameVirtualHost *

<VirtualHost www.domain1.com>
...
</VirtualHost>

<VirtualHost www.domain2.com>
...
</VirtualHost>

### End httpd.conf ###

After restarting apache (/sbin/service httpd restart) here's the error:

Starting httpd: [Fri Mar  1 11:20:28 2002] [warn] VirtualHost
www.eccod.com:80 overlaps with VirtualHost www.riodo.ath.cx:80, the
first has precedence, perhaps
you need a NameVirtualHost directive
[Fri Mar  1 11:20:28 2002] [warn] NameVirtualHost *:80 has no VirtualHosts

and going to www.domain1.com works just fine, but when going to
www.domain2.com, you still get www.domain1.com.

Michael, here's what you need:

### Begin sample httpd.conf ###
# note it doesn't matter what you put for the *server* settings above
the virtual host lines, as
# that's all ignored if you use virtual hosts.  (i.e. leave the modules,
etc...)

NameVirtualHost *

<VirtualHost *>
ServerAdmin email at domain1.com
DocumentRoot /www/domain1.com/htdocs
ServerName www.domain1.com
ErrorLog logs/error_log
CustomLog /www/domain1.com/logs/access_log common
CustomLog /www/domain1.com/logs/referer_log referer
CustomLog /www.domain1.com/logs/agent_log agent
CustomLog /www.domain1.com/logs/access_log combined
</VirtualHost>
ServerAdmin email at domain2.com
DocumentRoot /www/domain2.com/htdocs
ServerName www.domain2.com
ErrorLog /www/domain2.com/logs/error_log
CustomLog /www/domain2.com/logs/access_log common
CustomLog /www/domain2.com/logs/referer_log referer
CustomLog /www.domain2.com/logs/agent_log agent
CustomLog /www.domain2.com/logs/access_log combined
<VirtualHost *>

### End sample httpd.conf ###

After a restart of Apache, there are no errors (or warnings), just a
clean stop, start.

As the Apache documentation says..."Just about every directive can be
placed inside a <VirtualHost *> directive."  So, your directory
directives, access directives, etc...they all go  inside each
<VirtualHost *> directive.

This, at least, works for me, and it works great.  I'm hosting 3 sites
this way and have had no problems whatsoever.  For those who are
interested, or want to know, I have Apache configured for both php and
Apache::ASP (with mod_perl).  One of my sites is done in PHP, and the
other is written in Perl/ASP.

-Lucas

Brian Densmore wrote:

>Bob, you're wrong, his statements are correct. But as Charles pointed
>out,
>Mike needs to add "www" to all of his lines, or try accessing the sites
>with http://domain1.com http://domain2.com .
>I tested this out on my site and that is exactly what the problem is.
>If I enter http://www.amason.net/ I get the amason site,
>if I enter http://www.rosefire.org/ I get the rosefire site,
>if I enter http://amason.net/ I get the amason site,
>if I enter http://rosefire.org I get the =-amason-= site! :)
>
>Thanks Charles for the tip.
>
>Brian
>
>>-----Original Message-----
>>From: Bob Stocker [mailto:bstocker at bloodtip.org]
>>Sent: Thursday, February 28, 2002 10:22 PM
>>To: Michael Pratt
>>Cc: kclug at kclug.org
>>Subject: Re: Apache Help
>>
>>
>>On Thu, 2002-02-28 at 21:36, Michael Pratt wrote:
>>
>>>This is Driving me bonkers!  IF I get rid od the primary
>>>
>>website out of the
>>
>>>virtual directory It works but if I add it back in all that
>>>
>>comes up on both
>>
>>>Domains it the Primary domain!!! UUUUUUHHHHHHHG!!!!! :((((((
>>>
>>>Mike
>>>
>>Hi there,
>>You're using the VirtualHost directive incorrectly.
>>The form should be <VirtualHost [IP address]> rather than <VirtualHost
>>[hostname]>.  So, for your purposes you could do <VirtualHost *> or
>><VirtualHost [DSL IP address]> for each of your virtual hosts.
>>From http://httpd.apache.org/docs-2.0/vhosts/name-based.html :
>>"Now when a request arrives, the server will first check if
>>it is using
>>an IP address that matches the NameVirtualHost. If it is, then it will
>>look at each <VirtualHost> section with a matching IP address
>>and try to
>>find one where the ServerName or ServerAlias matches the requested
>>hostname. If it finds one, then it uses the configuration for that
>>server. If no matching virtual host is found, then the first listed
>>virtual host that matches the IP address will be used."
>>
>>Good luck,
>>Bob
>>
>>>----- Original Message -----
>>>From: "Brian Densmore" <DensmoreB at ctbsonline.com>
>>>To: <mtpratt at swbell.net>; <kclug at kclug.org>
>>>Sent: Thursday, February 28, 2002 12:21 PM
>>>Subject: RE: Apache Help
>>>
>>>
>>>>Mike,
>>>>
>>>>  What does your: listen , bindaddress, usecanonicalname,
>>>>hostnamelookups lines look like?  Also what about the
>>>>
>>directory settings
>>
>>>>lines. You might try adding a document root line in each
>>>>
>>of the virtual
>>
>>>>domains.
>>>>
>>>>brian
>>>>
>>>>>-----Original Message-----
>>>>>From: Michael Pratt [mailto:mtpratt1971 at hotmail.com]
>>>>>Sent: Thursday, February 28, 2002 11:56 AM
>>>>>To: kclug at kclug.org
>>>>>Subject: Apache Help
>>>>>
>>>>>
>>>>>I am trying to set up multiple domains using one IP  I have
>>>>>this in my
>>>>>httpd.conf
>>>>>
>>>>>NameVirtualHost <DSL IP ADDRESS>
>>>>>
>>>>><VirtualHost domain1.net>
>>>>>DocumentRoot /var/www/html
>>>>>ServerName domain1.net
>>>>></VirtualHost>
>>>>>
>>>>><VirtualHost domain2.org>
>>>>>DocumentRoot /var/www/html/domain2
>>>>>ServerName domain2.org
>>>>></VirtualHost>
>>>>>
>>>>>The problem I have is no matter what domain I put in it goes
>>>>>to domain1.net
>>>>>
>>>>>how can I set Apache up to point Domain1 to /var/www/html and
>>>>>Domain2 to
>>>>>/var/www/html/domain2?
>>>>>
>>>>>
>>>>>Thanks!
>>>>>
>>>>>Mike
>>>>>
>>>>>
>>_________________________________________________________________
>>
>>>>>MSN Photos is the easiest way to share and print your photos:
>>>>>http://photos.msn.com/support/worldwide.aspx
>>>>>
>>>>>
>>>>>
>>>>>majordomo at kclug.org
>>>>>
>>>>
>>>>
>>majordomo at kclug.org
>>
>>>>
>>>
>>>
>>>
>>majordomo at kclug.org
>>
>>>
>>
>>
>>majordomo at kclug.org
>>
>
>
>





More information about the Kclug mailing list