Logformat for catching asked hostname in a *.domain.com scenario?

I have an Apache 2.2 VirtualHost with a *.example.com ServerName. This is required for my scenario, all subdomains are handled with the same site.

Now, in the access log, I am trying to figure out a LogFormat variable (or way) that will let me log the asked for domain name. If I use the vhost_combined format, all I get in my access log is *.example.com entries, not the actual vhost that was asked for.

Anyone know how to do this?


Solution 1:

You can use %{headername}i to put the contents of any header in the LogFormat directive, so %{Host}i will give you what the client put in the Host: header of the request, giving you exactly what you want.

See docs at http://httpd.apache.org/docs/2.2/mod/mod_log_config.html

Solution 2:

When you're using e.g. the vhost_combined Logformat:

CustomLog ${APACHE_LOG_DIR}/access.log vhost_combined

You can adapt vhost_combined by adding %{Host}i, e.g.

LogFormat "%v:%p %h %l %u %t %{Host}i \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined