Forum Moderators: phranque

Message Too Old, No Replies

virtualdocumentroot and logs per domain

instant subdomains

         

knegyesi

6:32 pm on Jun 9, 2004 (gmt 0)



If you would like to get instant subdomains AND logs per domain then read on. I've been tackling with this for a very long time, and there was no simple solution.

The request for subdomain.mydomain.tld shall be served from /var/www/htdocs/mydomain/subdomain and be logged to /var/log/apache/mydomain/access.log -- and this is the most important. The apache documentation does not help you if you want logs per domain. Yes, logs can be splitted, or you can use multilog daemon. Or...

First, you need to get a so-called wildcard entry in your DNS. I no longer host my own DNS, so the following lines which shall go to the zonefile are not checked:

* A 10.20.30.40

or

*.mydomain.tld. 14400 IN A 10.20.30.40

Second, we need to configure apache. You need the following lines in httpd.conf:

LoadModule vhost_alias_module /usr/lib/apache/1.3/mod_vhost_alias.so
NameVirtualHost 10.20.30.40
UseCanonicalName Off
Include vhosts/

The vhosts directory contains files like this:


<VirtualHost 10.20.30.40>
ServerName mydomain.tld
ServerAlias *.mydomain.tld
VirtualDocumentRoot /var/www/htdocs/%-2/%-3/
CustomLog /var/log/apache/mydomain/access.log combined
ErrorLog /var/log/apache/mydomain/error.log
</VirtualHost>

This file I simple named mydomain.

I put VirtualDocumentRoot inside the VirtualHost part 'cos this way I can serve HTTPS requests from other directories than the HTTP requests. If you are using another Apache for HTTPS, feel free to
put the VirtualDocumentRoot into the main httpd.conf as its value is domain agnostic.

Final note: beware, rewrite rules are a bit different with VirtualDocumentRoot. For example, the rewrite rule for the excellent drupal system had to be changed from index.php?q=$1 to
/index.php?q=$1 Sorry, I do not understand rewrite enough to know the reason for that...

jdMorgan

5:36 am on Jun 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



knegyesi,

Welcome to WebmasterWorld [webmasterworld.com]!

This is interesting. Where do the values for %-2 and %-3 come from?

Jim