7

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?

the
  • 468
  • 8
  • 23
Dhiraj Gupta
  • 173
  • 1
  • 1
  • 5

2 Answers2

16

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

the
  • 468
  • 8
  • 23
Aleksandar Ivanisevic
  • 3,327
  • 19
  • 24
5

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
the
  • 468
  • 8
  • 23