You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "R. Simons" <ro...@yahoo.com> on 2005/01/02 23:50:01 UTC

[users@httpd] Apache2 Configuring Virtual Servers/Hosts

Hi All,

After spending a lot of effort trying to get virtual
servers working on a SuSE's SLES9 server, I am posting
this in hopes of saving others the time.  Maybe I have
missed something in the documentation, but the
following configurations was the only way I could get
it to work.  I took a LAN trace, and I could see the
client was making request for the correct domain.  But
I was always seeing the first virtual server's web
page.

There was 2 things I had add/modify.

1) Create a conf file in the directory
/etc/apache2/vhost.d/ that has nothing but the
NameVirtualHost directive.

2) Changed <VirtualHost *:80> to <VirtualHost
192.168.0.15>.  This section created interesting
results depending what values I used.

Examples of failed configs

<VirtualHost *:80>
Results after doing "rcapache2 restart":
test:/etc/apache2/vhosts.d # rcapache2 restart
[Sun Jan 02 16:31:49 2005] [warn] _default_
VirtualHost overlap on port 80, the first has
precedence
Syntax OK
Shutting down httpd2 (waiting for all children to
terminate)         done
Starting httpd2 (prefork) [Sun Jan 02 16:31:49 2005]
[warn] _default_ VirtualHost overlap on port 80, the
first has precedence
                                                      
              done


<VirtualHost *>
Results after doing "rcapache2 restart":
test:/etc/apache2/vhosts.d # rcapache2 restart
Syntax OK
Shutting down httpd2 (waiting for all children to
terminate)         done
Starting httpd2 (prefork)                             
              done


<VirtualHost 192.168.0.15>
Results after doing "rcapache2 restart":
test:/etc/apache2/vhosts.d # rcapache2 restart
[Sun Jan 02 15:09:05 2005] [warn] VirtualHost
192.168.0.15:0 overlaps with VirtualHost
192.168.0.15:0, the first has precedence, perhaps you
need a NameVirtualHost directive
Syntax OK
Shutting down httpd2 (waiting for all children to
terminate)         done
Starting httpd2 (prefork) [Sun Jan 02 15:09:06 2005]
[warn] VirtualHost 192.168.0.15:0 overlaps with
VirtualHost 192.168.0.15:0, the first has precedence,
perhaps you need a NameVirtualHost directive
                                                      
              done


<VirtualHost www.c1thecat.com> and <VirtualHost
www.k2thecat.com>
Results after doing "rcapache2 restart":
test:/etc/apache2/vhosts.d # rcapache2 restart
[Sun Jan 02 14:59:39 2005] [warn] VirtualHost
www.c1thecat.com:0 overlaps with VirtualHost
www.k2thecat.com:0, the first has precedence, perhaps
you need a NameVirtualHost directive
Syntax OK
Shutting down httpd2 (waiting for all children to
terminate)         done
Starting httpd2 (prefork) [Sun Jan 02 14:59:39 2005]
[warn] VirtualHost www.c1thecat.com:0 overlaps with
VirtualHost www.k2thecat.com:0, the first has
precedence, perhaps you need a NameVirtualHost
directive
                                                      
              done


Here is my working configuration.


Apache2 Version:
test:~ # rpm -q apache2
apache2-2.0.49-27.8


My conf files:
test:/etc/apache2/vhosts.d # ls
.
..
c1thecat-vhost.conf ...	First Domain
k2thecat-vhost.conf ...	Second Domain
namevhost.conf	.......	My NameVirtualHost directive
conf file
vhost-ssl.template
vhost.template


Contents of namevhost.conf:
test:/etc/apache2/vhosts.d # cat namevhost.conf
NameVirtualHost 192.168.0.15


Contents of c1thecat-vhost.conf:
test:/etc/apache2/vhosts.d # cat c1thecat-vhost.conf
<VirtualHost 192.168.0.15>
    ServerAdmin webmaster@c1thecat.com 
    ServerName www.c1thecat.com 
    DocumentRoot /srv/www/vhosts/c1thecat.com
    ErrorLog /var/log/apache2/c1thecat.com-error_log
    CustomLog /var/log/apache2/c1thecat.com-access_log
combined

    # don't loose time with IP address lookups
    HostnameLookups Off

    # needed for named virtual hosts
    UseCanonicalName Off

    # configures the footer on server-generated
documents
    ServerSignature On

    ScriptAlias /cgi-bin/
"/srv/www/vhosts/c1thecat.com/cgi-bin/"

    <Directory "/srv/www/vhosts/c1thecat.com/cgi-bin">
        AllowOverride None
        Options +ExecCGI -Includes
        Order allow,deny
        Allow from all
    </Directory>

    <IfModule mod_userdir.c>
        UserDir public_html
        Include /etc/apache2/mod_userdir.conf
    </IfModule>

    <Directory "/srv/www/vhosts/c1thecat.com">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>


Contents of k2thecat-vhost.conf:
test:/etc/apache2/vhosts.d # cat k2thecat-vhost.conf
<VirtualHost 192.168.0.15>
    ServerAdmin webmaster@.k2thecat.com 
    ServerName www.k2thecat.com 
    DocumentRoot /srv/www/vhosts/k2thecat.com
    ErrorLog /var/log/apache2/k2thecat.com-error_log
    CustomLog /var/log/apache2/k2thecat.com-access_log
combined

    # don't loose time with IP address lookups
    HostnameLookups Off

    # needed for named virtual hosts
    UseCanonicalName Off

    # configures the footer on server-generated
documents
    ServerSignature On

    ScriptAlias /cgi-bin/
"/srv/www/vhosts/k2thecat.com/cgi-bin/"

    <Directory "/srv/www/vhosts/k2thecat.com/cgi-bin">
        AllowOverride None
        Options +ExecCGI -Includes
        Order allow,deny
        Allow from all
    </Directory>

    <IfModule mod_userdir.c>
        UserDir public_html
        Include /etc/apache2/mod_userdir.conf
    </IfModule>

    <Directory "/srv/www/vhosts/k2thecat.com">
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>


My documentroot directories:
test:/srv/www/vhosts # ls
.
..
c1thecat.com
k2thecat.com


Last 25 lines of httpd.conf: 
test:~ # tail -25 /etc/apache2/httpd.conf
### Virtual server configuration
############################################
#
# VirtualHost: If you want to maintain multiple
domains/hostnames on your
# machine you can setup VirtualHost containers for
them. Most configurations
# use only name-based virtual hosts so the server
doesn't need to worry about
# IP addresses. This is indicated by the asterisks in
the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.0/vhosts/>
# for further details before you try to setup virtual
hosts.
#
# You may use the command line option '-S' to verify
your virtual host
# configuration.
#

Include /etc/apache2/vhosts.d/*.conf


# Note: instead of adding your own configuration here,
consider
#       adding it in your own file
(/etc/apache2/httpd.conf.local)
#       putting its name into
APACHE_CONF_INCLUDE_FILES in
#       /etc/sysconfig/apache2 -- this will make
system updates
#       easier :)


		
__________________________________ 
Do you Yahoo!? 
Send holiday email and support a worthy cause. Do good. 
http://celebrity.mail.yahoo.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Apache2 Configuring Virtual Servers/Hosts

Posted by "R. Simons" <ro...@yahoo.com>.
Update 

After reading additional posts, it looks like the
NameVirtualHost and VirtualHost must match.

example:

If NameVirtualHost is defined as *:80, then
VirtualHost must be <VirtualHost *:80>

or

If NameVirtualHost is defined as 192.168.0.15, then
VirtualHost must be <VirtualHost 192.168.0.15>

--- "R. Simons" <ro...@yahoo.com> wrote:

> Hi All,
> 
> After spending a lot of effort trying to get virtual
> servers working on a SuSE's SLES9 server, I am
> posting
> this in hopes of saving others the time.  Maybe I
> have
> missed something in the documentation, but the
> following configurations was the only way I could
> get
> it to work.  I took a LAN trace, and I could see the
> client was making request for the correct domain. 
> But
> I was always seeing the first virtual server's web
> page.
> 
> There was 2 things I had add/modify.
> 
> 1) Create a conf file in the directory
> /etc/apache2/vhost.d/ that has nothing but the
> NameVirtualHost directive.
> 
> 2) Changed <VirtualHost *:80> to <VirtualHost
> 192.168.0.15>.  This section created interesting
> results depending what values I used.
> 
> Examples of failed configs
> 
> <VirtualHost *:80>
> Results after doing "rcapache2 restart":
> test:/etc/apache2/vhosts.d # rcapache2 restart
> [Sun Jan 02 16:31:49 2005] [warn] _default_
> VirtualHost overlap on port 80, the first has
> precedence
> Syntax OK
> Shutting down httpd2 (waiting for all children to
> terminate)         done
> Starting httpd2 (prefork) [Sun Jan 02 16:31:49 2005]
> [warn] _default_ VirtualHost overlap on port 80, the
> first has precedence
>                                                     
>  
>               done
> 
> 
> <VirtualHost *>
> Results after doing "rcapache2 restart":
> test:/etc/apache2/vhosts.d # rcapache2 restart
> Syntax OK
> Shutting down httpd2 (waiting for all children to
> terminate)         done
> Starting httpd2 (prefork)                           
>  
>               done
> 
> 
> <VirtualHost 192.168.0.15>
> Results after doing "rcapache2 restart":
> test:/etc/apache2/vhosts.d # rcapache2 restart
> [Sun Jan 02 15:09:05 2005] [warn] VirtualHost
> 192.168.0.15:0 overlaps with VirtualHost
> 192.168.0.15:0, the first has precedence, perhaps
> you
> need a NameVirtualHost directive
> Syntax OK
> Shutting down httpd2 (waiting for all children to
> terminate)         done
> Starting httpd2 (prefork) [Sun Jan 02 15:09:06 2005]
> [warn] VirtualHost 192.168.0.15:0 overlaps with
> VirtualHost 192.168.0.15:0, the first has
> precedence,
> perhaps you need a NameVirtualHost directive
>                                                     
>  
>               done
> 
> 
> <VirtualHost www.c1thecat.com> and <VirtualHost
> www.k2thecat.com>
> Results after doing "rcapache2 restart":
> test:/etc/apache2/vhosts.d # rcapache2 restart
> [Sun Jan 02 14:59:39 2005] [warn] VirtualHost
> www.c1thecat.com:0 overlaps with VirtualHost
> www.k2thecat.com:0, the first has precedence,
> perhaps
> you need a NameVirtualHost directive
> Syntax OK
> Shutting down httpd2 (waiting for all children to
> terminate)         done
> Starting httpd2 (prefork) [Sun Jan 02 14:59:39 2005]
> [warn] VirtualHost www.c1thecat.com:0 overlaps with
> VirtualHost www.k2thecat.com:0, the first has
> precedence, perhaps you need a NameVirtualHost
> directive
>                                                     
>  
>               done
> 
> 
> Here is my working configuration.
> 
> 
> Apache2 Version:
> test:~ # rpm -q apache2
> apache2-2.0.49-27.8
> 
> 
> My conf files:
> test:/etc/apache2/vhosts.d # ls
> .
> ..
> c1thecat-vhost.conf ...	First Domain
> k2thecat-vhost.conf ...	Second Domain
> namevhost.conf	.......	My NameVirtualHost directive
> conf file
> vhost-ssl.template
> vhost.template
> 
> 
> Contents of namevhost.conf:
> test:/etc/apache2/vhosts.d # cat namevhost.conf
> NameVirtualHost 192.168.0.15
> 
> 
> Contents of c1thecat-vhost.conf:
> test:/etc/apache2/vhosts.d # cat c1thecat-vhost.conf
> <VirtualHost 192.168.0.15>
>     ServerAdmin webmaster@c1thecat.com 
>     ServerName www.c1thecat.com 
>     DocumentRoot /srv/www/vhosts/c1thecat.com
>     ErrorLog /var/log/apache2/c1thecat.com-error_log
>     CustomLog
> /var/log/apache2/c1thecat.com-access_log
> combined
> 
>     # don't loose time with IP address lookups
>     HostnameLookups Off
> 
>     # needed for named virtual hosts
>     UseCanonicalName Off
> 
>     # configures the footer on server-generated
> documents
>     ServerSignature On
> 
>     ScriptAlias /cgi-bin/
> "/srv/www/vhosts/c1thecat.com/cgi-bin/"
> 
>     <Directory
> "/srv/www/vhosts/c1thecat.com/cgi-bin">
>         AllowOverride None
>         Options +ExecCGI -Includes
>         Order allow,deny
>         Allow from all
>     </Directory>
> 
>     <IfModule mod_userdir.c>
>         UserDir public_html
>         Include /etc/apache2/mod_userdir.conf
>     </IfModule>
> 
>     <Directory "/srv/www/vhosts/c1thecat.com">
>         Options Indexes FollowSymLinks
>         AllowOverride None
>         Order allow,deny
>         Allow from all
>     </Directory>
> 
> </VirtualHost>
> 
> 
> Contents of k2thecat-vhost.conf:
> test:/etc/apache2/vhosts.d # cat k2thecat-vhost.conf
> <VirtualHost 192.168.0.15>
>     ServerAdmin webmaster@.k2thecat.com 
>     ServerName www.k2thecat.com 
>     DocumentRoot /srv/www/vhosts/k2thecat.com
>     ErrorLog /var/log/apache2/k2thecat.com-error_log
>     CustomLog
> /var/log/apache2/k2thecat.com-access_log
> combined
> 
>     # don't loose time with IP address lookups
>     HostnameLookups Off
> 
>     # needed for named virtual hosts
>     UseCanonicalName Off
> 
>     # configures the footer on server-generated
> documents
>     ServerSignature On
> 
>     ScriptAlias /cgi-bin/
> "/srv/www/vhosts/k2thecat.com/cgi-bin/"
> 
>     <Directory
> "/srv/www/vhosts/k2thecat.com/cgi-bin">
>         AllowOverride None
>         Options +ExecCGI -Includes
>         Order allow,deny
>         Allow from all
> 
=== message truncated ===



		
__________________________________ 
Do you Yahoo!? 
Send a seasonal email greeting and help others. Do good. 
http://celebrity.mail.yahoo.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org