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

I'd like to add a CustomLog directive to my apache configuration to log the full URL requested (or at least the host portion of the URL). I have several domains being handled by the same instance of apache, and would like to be able to distinguish the domains in the logs (as now all I see is "GET /"). I see in the documentation on LogFormat it lists %U to print the path portion of the URL, but I'm looking for the host.

share|improve this question

3 Answers 3

up vote 16 down vote accepted

Keep reading the LogFormat documentation and you'll find:

%...{Foobar}i:  The contents of Foobar: header line(s) in the request
                sent to the server.

Which means you could include in your configuration:

%{Host}i

The %v and %V directives may also get you what you want.

%v will always be the value of ServerName (the "canonical name" of your virtual host). %V may be the value of ServerName, or it may be the value of the HTTP Host header, depending on whether or not you have UseCanonicalName enabled in your configuration (and whether or not the client supplied a Host header).

share|improve this answer
    
Will %{Host}i work even for HTTP/1.0? %V looks right at first glance, thanks! –  jrdioko Jun 23 '11 at 17:49
    
I believe that %{Host}i (or any %{...}i construct) will only produce a result if that header actually exists in the request. So for HTTP/1.0, I would not expect it to be useful. –  larsks Jun 23 '11 at 17:51
    
One more clarification: So %V will be identical to %{Host}i if UseCanonicalName is disabled? –  jrdioko Jun 23 '11 at 18:29
1  
According to the documentation, "With UseCanonicalName off Apache will form self-referential URLs using the hostname and port supplied by the client if any are supplied (otherwise it will use the canonical name, as defined above)." So %V will use ServerName if there is no Host header. –  larsks Jun 23 '11 at 18:46

'%v' is the ServerName might be what you want?

share|improve this answer
    
It looks like %v always returns the same string in my situation: the ServerName value regardless of what domain appears in the URL. But %V looks like it does the right thing. –  jrdioko Jun 23 '11 at 17:48

Add %v to your log format.

Something like this:

LogFormat "%v - %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined-vhost
CustomLog /log/file/location combined-vhost
share|improve this answer
1  
It looks like %v always returns the same string in my situation: the ServerName value regardless of what domain appears in the URL. But %V looks like it does the right thing. –  jrdioko Jun 23 '11 at 17:47

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.