You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Clay Porter <cl...@gmail.com> on 2012/01/12 22:21:06 UTC

[users@httpd] Name Virtual Host Weirdness

All,

I have two virtual hosts set up that look like the following (I've
tried to only include the information pertaining to the problem, i,e,
I've removed the actual rewrite rules, etc):

Listen *:38215
NameVirtualHost *:38215

<VirtualHost *:38215>
    DocumentRoot /www/sitea
    ServerName www.sitea.com
    ErrorLog logs/sitea-error.log
    CustomLog logs/sitea-access.log common

    <IfModule mod_rewrite.c>
        RewriteEngine on
#        RewriteLog  logs/sitea-rewrite.log
#        RewriteLogLevel 3
    </IfModule>
</VirtualHost>

<VirtualHost *:38215>
    DocumentRoot /www/siteb
    ServerName www.siteb.com
    ErrorLog logs/siteb-error.log
    CustomLog logs/siteb-access.log common

    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteLog  logs/sitea-rewrite.log
        RewriteLogLevel 3
    </IfModule>
</VirtualHost>

What's happening is that all of the log information is being written
to sitea's log files, no matter which virtual host I hit.  The log
files for siteb are being created at start up but they are empty.  I'm
afraid this weirdness might also be affecting the rewrite rules
specific to the sites. Does anyone know why this might be happening?

I'm using Apache 2.2.3 on a RHEL 5.6 box.

Thanks for any help you can give.  Please let me know if I need to
provide more info than this.

---------------------------------------------------------------------
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] Name Virtual Host Weirdness

Posted by Steve Swift <Sw...@swiftys.org.uk>.
One more comment on the "defunct vhost" setup.
You have to be very careful if you decide to define each of your virtual
hosts in their own distinct definition file, and include them all with a
wildcard Include directive, such as "Include vhost.*"

I think that the order that the files are included is alphabetical.
Whatever it is, the order can easily be changed by introducing new files,
which might not get included where you expect in the sequence. More
importantly, the vhost which is first (default) may change unexpectedly.
This is what happened to us.

I have a webpage on our server which displays the effective httpd.conf with
all of the "include"s expanded out. I recently added a case-sensitive
alphabetical sort on filename when an include directive references multiple
files, so that's what my research identified a few months ago.

On 13 January 2012 16:29, Tom Evans <te...@googlemail.com> wrote:

> On Fri, Jan 13, 2012 at 4:13 PM, Clay Porter <cl...@gmail.com>
> wrote:
> > Thanks for the info.  I will try what you suggested.
> >
> > I'm pretty new to all of this, so I hope you don't mind a n00b
> > question.  What do you mean by a "defunct vhost"?  Could I trouble you
> > for an example?
> >
> > Thanks again.
> >
> > Clay
> >
>
> He means a vhost is not used for serving the sites you want to serve,
> and only serves when a request is received that doesn't match one of
> your real vhosts, which Apache by default will serve from the first
> applicable vhost listed in the configuration.
>
> Eg if you have this configuration:
>
> NameVirtualHost *:80
>
> <VirtualHost *:80>
>  ServerName foo
> </VirtualHost>
>
> <VirtualHost *:80>
>  ServerName bar
> </VirtualHost>
>
> and a request comes in on port 80 with server name 'wibble', then none
> of these vhosts match, and Apache will serve from the first listed
> vhost, in this case the 'foo' vhost.
>
> If the configuration was like this:
>
> NameVirtualHost *:80
>
> <VirtualHost *:80>
>  DocumentRoot /var/empty
> </VirtualHost>
>
> <VirtualHost *:80>
>  ServerName foo
> </VirtualHost>
>
> <VirtualHost *:80>
>  ServerName bar
> </VirtualHost>
>
> then a request for the host 'wibble' would be served from the first
> unnamed vhost. This helps make it clear that a request was correctly
> routed to the right vhost, and didn't just get there because the vhost
> was the first listed and hence default.
>
> Cheers
>
> Tom
>
> ---------------------------------------------------------------------
> 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
>
>


-- 
Steve Swift
http://www.swiftys.org.uk

Re: [users@httpd] Name Virtual Host Weirdness

Posted by Tom Evans <te...@googlemail.com>.
On Fri, Jan 13, 2012 at 4:13 PM, Clay Porter <cl...@gmail.com> wrote:
> Thanks for the info.  I will try what you suggested.
>
> I'm pretty new to all of this, so I hope you don't mind a n00b
> question.  What do you mean by a "defunct vhost"?  Could I trouble you
> for an example?
>
> Thanks again.
>
> Clay
>

He means a vhost is not used for serving the sites you want to serve,
and only serves when a request is received that doesn't match one of
your real vhosts, which Apache by default will serve from the first
applicable vhost listed in the configuration.

Eg if you have this configuration:

NameVirtualHost *:80

<VirtualHost *:80>
  ServerName foo
</VirtualHost>

<VirtualHost *:80>
  ServerName bar
</VirtualHost>

and a request comes in on port 80 with server name 'wibble', then none
of these vhosts match, and Apache will serve from the first listed
vhost, in this case the 'foo' vhost.

If the configuration was like this:

NameVirtualHost *:80

<VirtualHost *:80>
  DocumentRoot /var/empty
</VirtualHost>

<VirtualHost *:80>
  ServerName foo
</VirtualHost>

<VirtualHost *:80>
  ServerName bar
</VirtualHost>

then a request for the host 'wibble' would be served from the first
unnamed vhost. This helps make it clear that a request was correctly
routed to the right vhost, and didn't just get there because the vhost
was the first listed and hence default.

Cheers

Tom

---------------------------------------------------------------------
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] Name Virtual Host Weirdness

Posted by Clay Porter <cl...@gmail.com>.
Thanks for the info.  I will try what you suggested.

I'm pretty new to all of this, so I hope you don't mind a n00b
question.  What do you mean by a "defunct vhost"?  Could I trouble you
for an example?

Thanks again.

Clay

On Thu, Jan 12, 2012 at 4:46 PM, Steve Swift <Sw...@swiftys.org.uk> wrote:
> It all looks correct to me. Can you exchange the order of the VirtualHost
> definitions? The first Virtualhost defined is the one that gets used if
> anything goes wrong with allocating a request to a particular vhost, so you
> often end up thinking you are using the first Vhost  when in fact you are
> using the default vhost.
>
> I tend to define a defunct vhost first - one with nothing in the
> documentroot, except an error document which is served in response to every
> URI. This makes errors less puzzling.
>
> On 12 January 2012 21:21, Clay Porter <cl...@gmail.com> wrote:
>>
>> All,
>>
>> I have two virtual hosts set up that look like the following (I've
>> tried to only include the information pertaining to the problem, i,e,
>> I've removed the actual rewrite rules, etc):
>>
>> Listen *:38215
>> NameVirtualHost *:38215
>>
>> <VirtualHost *:38215>
>>    DocumentRoot /www/sitea
>>    ServerName www.sitea.com
>>    ErrorLog logs/sitea-error.log
>>    CustomLog logs/sitea-access.log common
>>
>>    <IfModule mod_rewrite.c>
>>        RewriteEngine on
>> #        RewriteLog  logs/sitea-rewrite.log
>> #        RewriteLogLevel 3
>>    </IfModule>
>> </VirtualHost>
>>
>> <VirtualHost *:38215>
>>    DocumentRoot /www/siteb
>>    ServerName www.siteb.com
>>    ErrorLog logs/siteb-error.log
>>    CustomLog logs/siteb-access.log common
>>
>>    <IfModule mod_rewrite.c>
>>        RewriteEngine on
>>        RewriteLog  logs/sitea-rewrite.log
>>        RewriteLogLevel 3
>>    </IfModule>
>> </VirtualHost>
>>
>> What's happening is that all of the log information is being written
>> to sitea's log files, no matter which virtual host I hit.  The log
>> files for siteb are being created at start up but they are empty.  I'm
>> afraid this weirdness might also be affecting the rewrite rules
>> specific to the sites. Does anyone know why this might be happening?
>>
>> I'm using Apache 2.2.3 on a RHEL 5.6 box.
>>
>> Thanks for any help you can give.  Please let me know if I need to
>> provide more info than this.
>>
>> ---------------------------------------------------------------------
>> 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
>>
>
>
>
> --
> Steve Swift
> http://www.swiftys.org.uk

---------------------------------------------------------------------
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] Name Virtual Host Weirdness

Posted by Steve Swift <Sw...@swiftys.org.uk>.
It all looks correct to me. Can you exchange the order of the VirtualHost
definitions? The first Virtualhost defined is the one that gets used if
anything goes wrong with allocating a request to a particular vhost, so you
often end up thinking you are using the first Vhost  when in fact you are
using the default vhost.

I tend to define a defunct vhost first - one with nothing in the
documentroot, except an error document which is served in response to every
URI. This makes errors less puzzling.

On 12 January 2012 21:21, Clay Porter <cl...@gmail.com> wrote:

> All,
>
> I have two virtual hosts set up that look like the following (I've
> tried to only include the information pertaining to the problem, i,e,
> I've removed the actual rewrite rules, etc):
>
> Listen *:38215
> NameVirtualHost *:38215
>
> <VirtualHost *:38215>
>    DocumentRoot /www/sitea
>    ServerName www.sitea.com
>    ErrorLog logs/sitea-error.log
>    CustomLog logs/sitea-access.log common
>
>    <IfModule mod_rewrite.c>
>        RewriteEngine on
> #        RewriteLog  logs/sitea-rewrite.log
> #        RewriteLogLevel 3
>    </IfModule>
> </VirtualHost>
>
> <VirtualHost *:38215>
>    DocumentRoot /www/siteb
>    ServerName www.siteb.com
>    ErrorLog logs/siteb-error.log
>    CustomLog logs/siteb-access.log common
>
>    <IfModule mod_rewrite.c>
>        RewriteEngine on
>        RewriteLog  logs/sitea-rewrite.log
>        RewriteLogLevel 3
>    </IfModule>
> </VirtualHost>
>
> What's happening is that all of the log information is being written
> to sitea's log files, no matter which virtual host I hit.  The log
> files for siteb are being created at start up but they are empty.  I'm
> afraid this weirdness might also be affecting the rewrite rules
> specific to the sites. Does anyone know why this might be happening?
>
> I'm using Apache 2.2.3 on a RHEL 5.6 box.
>
> Thanks for any help you can give.  Please let me know if I need to
> provide more info than this.
>
> ---------------------------------------------------------------------
> 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
>
>


-- 
Steve Swift
http://www.swiftys.org.uk