You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Alberto Giménez <la...@gmail.com> on 2007/03/16 10:41:42 UTC

[users@httpd] Handling VirtualDocumentRoot inside VirtualHosts

(First of all, sorry for my english, its not my native language so you
can read some basic/strange language constructions here :)

Hi, I'm facing a problem with my Apache (1.3.33) setup, I expose the scenario:

One single machine is serving several domains (about 300 or so). One
of them has thousands of visits a day (95% of daily load) and the
other domains have very low traffic.

I use awstats to parse the access_log file and get visit stats on a
daily basis, but it's growing up a lot. I parse the logfile with
awstats_updateall, and what it does is just parse the same log again
and again for each domain (remember, about 300)

So, I have an access_log with 95% of hits for only one domain, and the
other 300 domains are parsing the same big BIG file to just get 10
hits or so. It is very inefficient, isn't it?

The current setup is with a VirtualDocumentRoot directive on server
environment, so all domains are treated the same way. And I'd like to
distinguish the main domain from the oters so parsing speeds up and
gets more effective:

Hits to main domain go to one access_log file
Hits to any other domain go to *one* single access_log file, so calls
to awstats are against this only logfile. This way I get smaller file
(and quicker to parse) for the 300 domains.

I got a working setup but I doutbt if it works because I configured it
properly, or is kind of "collateral" effect of apache conffile-parsing
(This is a local network machine, i didn't test it in production
environment :):

NameVirtualHost 192.168.0.150
UseCanonicalName Off
LogLevel debug


<VirtualHost 192.168.0.150>
        VirtualDocumentRoot /var/www/sites/%-2.1/%-2.2/%-2.3/%-2.0.%-1/
  DirectoryIndex index.php index.html
  CustomLog /var/log/apache/webs_access_log vspecial
</VirtualHost>


<VirtualHost 192.168.0.150>
        ServerName www.portal.com
        ServerAlias portal.com
        DocumentRoot /var/www/portal/
        CustomLog /var/log/apache/access_log vspecial
        DirectoryIndex index.html index.cgi index.pl index.php
</VirtualHost>

I deduced that, as I use the ServerName directive, it just matches the
second VirtualHost if the request is *only* to that name, and uses the
first one in all other cases. Is that correct? Is that setup OK, or is
it working accidentally??

I tried several combinations:
If I switch Vhosts definition order, it doesn't work.
If I use <VirtualHost www.abcd.com> in the first entry, it works also
for all domains (why? because it is the first one and therefore the
default?).

Could someone please throw some light? I've been searching for mass
virtual hosting with separate logs (not for ALL, but the setup I
exposed here) but didn't find nothing interesting, and I found Apache
documentation a little poor on that topic. Does anyone have a pointer
on how does apache treat internally all the vhosts thing?

Thanks in advance!

-- 
Alberto Giménez

---------------------------------------------------------------------
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] Handling VirtualDocumentRoot inside VirtualHosts

Posted by matt farey <ma...@gmail.com>.

Alberto Giménez wrote:
> On 3/16/07, matt farey <ma...@gmail.com> wrote:
>>
>> anything which doesnt match a hostname will use the first defined
>> virtualhost,
>>
>> I do not have
>> <VirtualHost 192.168.0.150>
>>        VirtualDocumentRoot /var/www/sites/%-2.1/%-2.2/%-2.3/%-2.0.%-1/
>>  DirectoryIndex index.php index.html
>>  CustomLog /var/log/apache/webs_access_log vspecial
>> </VirtualHost>
>>
>> I only have
>>
>>  VirtualDocumentRoot /var/www/sites/%-2.1/%-2.2/%-2.3/%-2.0.%-1/
>>  DirectoryIndex index.php index.html
>>  CustomLog /var/log/apache/webs_access_log vspecial
>>
>> at the end after all my virtualhost definitions
>
> I've tried it, but it misworked. As the "main" www.portal.com domain
> was the first defined virtual host, then all other domain requests
> used that definition, EVEN if doman name was diferent, so requests to
> www.abcd.com are logged to portal_access_log instead of
> webs_access_log. Quite strange, the VirtualDocRoot thing worked, is
> just the Log what didn't work :?. Any idea?
>
> Anyway, I'm trying different combinations, I'll report strange things :)
>
No it was my fault, I should hav mentioned that I am using the latest
2.2.x build, sorry about that.
What you are doing seems fine though, however it works, keep it that way!

-- 
Matthew Farey



---------------------------------------------------------------------
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] Handling VirtualDocumentRoot inside VirtualHosts

Posted by Alberto Giménez <la...@gmail.com>.
On 3/16/07, matt farey <ma...@gmail.com> wrote:
>
> anything which doesnt match a hostname will use the first defined
> virtualhost,
>
> I do not have
> <VirtualHost 192.168.0.150>
>        VirtualDocumentRoot /var/www/sites/%-2.1/%-2.2/%-2.3/%-2.0.%-1/
>  DirectoryIndex index.php index.html
>  CustomLog /var/log/apache/webs_access_log vspecial
> </VirtualHost>
>
> I only have
>
>  VirtualDocumentRoot /var/www/sites/%-2.1/%-2.2/%-2.3/%-2.0.%-1/
>  DirectoryIndex index.php index.html
>  CustomLog /var/log/apache/webs_access_log vspecial
>
> at the end after all my virtualhost definitions

I've tried it, but it misworked. As the "main" www.portal.com domain
was the first defined virtual host, then all other domain requests
used that definition, EVEN if doman name was diferent, so requests to
www.abcd.com are logged to portal_access_log instead of
webs_access_log. Quite strange, the VirtualDocRoot thing worked, is
just the Log what didn't work :?. Any idea?

Anyway, I'm trying different combinations, I'll report strange things :)

-- 
Alberto Giménez

---------------------------------------------------------------------
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] Handling VirtualDocumentRoot inside VirtualHosts

Posted by matt farey <ma...@gmail.com>.

Alberto Giménez wrote:
> (First of all, sorry for my english, its not my native language so you
> can read some basic/strange language constructions here :)
>
> Hi, I'm facing a problem with my Apache (1.3.33) setup, I expose the
> scenario:
>
> One single machine is serving several domains (about 300 or so). One
> of them has thousands of visits a day (95% of daily load) and the
> other domains have very low traffic.
>
> I use awstats to parse the access_log file and get visit stats on a
> daily basis, but it's growing up a lot. I parse the logfile with
> awstats_updateall, and what it does is just parse the same log again
> and again for each domain (remember, about 300)
>
> So, I have an access_log with 95% of hits for only one domain, and the
> other 300 domains are parsing the same big BIG file to just get 10
> hits or so. It is very inefficient, isn't it?
>
> The current setup is with a VirtualDocumentRoot directive on server
> environment, so all domains are treated the same way. And I'd like to
> distinguish the main domain from the oters so parsing speeds up and
> gets more effective:
>
> Hits to main domain go to one access_log file
> Hits to any other domain go to *one* single access_log file, so calls
> to awstats are against this only logfile. This way I get smaller file
> (and quicker to parse) for the 300 domains.
>
> I got a working setup but I doutbt if it works because I configured it
> properly, or is kind of "collateral" effect of apache conffile-parsing
> (This is a local network machine, i didn't test it in production
> environment :):
>
> NameVirtualHost 192.168.0.150
> UseCanonicalName Off
> LogLevel debug
>
>
> <VirtualHost 192.168.0.150>
>        VirtualDocumentRoot /var/www/sites/%-2.1/%-2.2/%-2.3/%-2.0.%-1/
>  DirectoryIndex index.php index.html
>  CustomLog /var/log/apache/webs_access_log vspecial
> </VirtualHost>
>
>
> <VirtualHost 192.168.0.150>
>        ServerName www.portal.com
>        ServerAlias portal.com
>        DocumentRoot /var/www/portal/
>        CustomLog /var/log/apache/access_log vspecial
>        DirectoryIndex index.html index.cgi index.pl index.php
> </VirtualHost>
>
> I deduced that, as I use the ServerName directive, it just matches the
> second VirtualHost if the request is *only* to that name, and uses the
> first one in all other cases. Is that correct? Is that setup OK, or is
> it working accidentally??
It is correct, I useDCMVH too, just like you I have 1 main with
thousands and a hundred smaller ones, I do exactly what you do to
separate them - two access log files, except that I also have two error
logs as well.
>
> I tried several combinations:
> If I switch Vhosts definition order, it doesn't work.
I dont understand why, if the host matches it should use whatever
virtualhost has that servername, whatever the order
> If I use <VirtualHost www.abcd.com> in the first entry, it works also
> for all domains (why? because it is the first one and therefore the
> default?).
anything which doesnt match a hostname will use the first defined
virtualhost,

I do not have
<VirtualHost 192.168.0.150>
       VirtualDocumentRoot /var/www/sites/%-2.1/%-2.2/%-2.3/%-2.0.%-1/
 DirectoryIndex index.php index.html
 CustomLog /var/log/apache/webs_access_log vspecial
</VirtualHost>

I only have

 VirtualDocumentRoot /var/www/sites/%-2.1/%-2.2/%-2.3/%-2.0.%-1/
 DirectoryIndex index.php index.html
 CustomLog /var/log/apache/webs_access_log vspecial

at the end after all my virtualhost definitions
>
> Could someone please throw some light? I've been searching for mass
> virtual hosting with separate logs (not for ALL, but the setup I
> exposed here) but didn't find nothing interesting, and I found Apache
> documentation a little poor on that topic. Does anyone have a pointer
> on how does apache treat internally all the vhosts thing?
you are doing fine, this is how it works, and you can define every other
thing there as well, you can have custom rewrites, bandwidth rules, but
the trick is, every time you want a particular servername to be
configured different you have to supply a virtualhost definition to go
with the new rules.

matt
>
> Thanks in advance!
>




---------------------------------------------------------------------
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