Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a virtualhost setup with usecanonicalname off.

I have ServerName domain.com set and ServerAlias *.domain.com in the virtualhost.

Using apache2's %v LogFormat string will only capture domain.com, and I'm trying to get it to capture foo.domain.com so I can split logs accordingly.

LogFormat I'm currently using is

LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
share|improve this question

2 Answers 2

Using %{Host}i on your log format should give you the content of the "Host" header... which appears to be what you want.

Quote from the documentation:

%{Foobar}i - The contents of Foobar: header line(s) in the request sent to the server. Changes made by other modules (e.g. mod_headers) affect this. If you're interested in what the request header was prior to when most modules would have modified it, use mod_setenvif to copy the header into an internal environment variable and log that value with the %{VARNAME}e described above.

http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#formats

Hope this helps.

share|improve this answer

Why not just stick a separate CustomLog and ErrorLog directive into each virtual host definition?

<VirtualHost *:80>
ServerAdmin webmaster@place
DocumentRoot /var/www/hosted/place/root
ServerName www.place
AddHandler cgi-script .pl
CustomLog /var/www/hosted/place/logs/access_log combined
ErrorLog /var/www/hosted/place/logs/error_log
</VirtualHost>
share|improve this answer
    
Because I don't want to set a new virtualhost for every subdomain we have, there's no need for it, they all share the same directives. I want to accept requests for *.foo.com in one place, but have logs that say a.foo.com, b.foo.com, c.foo.com etc. –  imaginative Nov 20 '09 at 15:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.