3

We have an application which uses a DNS wildcard, i.e. *.app.example.com. We're using Apache 2.2 on Ubuntu Hardy. The relevant parts of the Apache config are as follows.

In /etc/apache2/httpd.conf:

LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vlog 

In /etc/apache2/sites-enabled/app.example.com:

ServerName app.example.com ServerAlias *.app.example.com ... CustomLog "|/usr/sbin/vlogger -s access.log /var/log/apache2/vlogger" vlog 

Clients access this application using their own URL, e.g. company1.app.example.com, company2.app.example.com, etc.

Previously, the %v in the LogFormat directive would match the hostname of the client request, and we'd get several subdirectories under /var/log/apache2/vlogger corresponding to the various client URLs in use.

Now, %v appears to be matching the ServerName value, so we only get one log under /var/log/apache2/vlogger/app.example.com. This breaks our logfile analysis because the log file has no indication of which client the log relates to.

I can fix this easily by changing the LogFormat to this:

LogFormat "%{Host}i %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vlog 

This will use the HTTP Host: header to tell vlogger which subdirectory to create the logs in and everything will be fine.

The only concern I have is that this has worked in the past and I can't find any indication that this has changed recently.

Is anyone else using a similar config, i.e. wildcard + vlogger and using %v? Is it working fine?

1
  • 1
    Graeme, it's the same over here. 2 installs of apache 2.0.54 and 2.2, both configured with LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined 2.0 shows the host header name (virtual host), 2.2 the host name. So it's not that you weren't right. BTW: Thanks for your "%{Host}i" :) Commented Jun 19, 2012 at 14:36

2 Answers 2

2

%v is and always has been the canonical name of the vserver, ive just checked the manuals for both 1.3, 2.0 and 2.2 and they all say

%...v: The canonical ServerName of the server serving the request. 

https://httpd.apache.org/docs/1.3/mod/mod_log_config.html

https://httpd.apache.org/docs/2.0/mod/mod_log_config.html

https://httpd.apache.org/docs/2.2/mod/mod_log_config.html

1
  • Yeah, I saw those.... somehow both I and my colleague had convinced ourselves/each other that we'd always used %v. Looking at all the evidence against us it seems we are wrong. We've changed it to use %{Host}i now, which is probably what it was previously anyway. :-/ Commented Apr 21, 2010 at 20:11
6

There is also %V (note the cap) and the useCanonicalName option

3
  • Thanks, but you're OT :) We were discussing how to log the (virtual host) name of the requested web site. Commented Jun 21, 2012 at 11:15
  • 2
    ...which is exactly what %V does. Logs the hostname of the virtual server which handled the request. The useCanonicalName option lets you control wether you want the server's opinion of it's name, or the client's opinion of the name. %{Host}i is always the client's opinion, so %V is another way to do that, plus a way to do what %{host}i cannot do. Commented Jun 21, 2012 at 14:49
  • This is the answer you were looking for, it's not OT. You were probably using the upcase %V and forgot. Commented Oct 30, 2015 at 14:31

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.