3

Is there a good way of viewing a detailed version of incoming requests to apache? At the minimum I'd like to check for the existence of a specific header and check its value. Requests are not coming from a browser, so it's tricky to view them going out. I'm not sure my custom HTTP header is actually being added by the client, so debugging my rewritecond directive is difficult.

2 Answers 2

4

You can create a custom LogFormat containing headers:

%{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.

Then reuse this LogFormat on your AccessLog directive

LogFormat "%v %h %l %u %t \"%r\" %>s %b %{MySpecialHeader}i " my_special_format
CustomLog logs/access_log_with_details my_special_format

Or even in one line only:

CustomLog logs/access_log_with_details "%v %h %l %u %t \"%r\" %>s %b %{MySpecialHeader}i"

UPDATE:

A note about the SetEnvIf:

This part is made to store the value of the Header on the start of any internal rewrite, and then then, instead of using the %{FOO}i syntax to extract the header at the end of the process you would use the %{MyEnvVar}e to log the value backuped at the beginning, this is the syntax to log an environment variable.

So ending with something like that:

SetEnvIf MySpecialHeader "(.*)" BACKUPHEADER=$1
(... stuff and things ...)
CustomLog logs/access_log_with_details "init: %{BACKUPHEADER}e final: %{MySpecialHeader}i "
3
  • Well, unfortunately it's just logging a "-" for the header name I specified, but it's a start! Perhaps that's why it's not working correctly.
    – AlexMA
    Nov 13, 2013 at 22:26
  • Could you explain how to do this part? "use mod_setenvif to copy the header into an internal environment variable"
    – AlexMA
    Nov 13, 2013 at 23:01
  • AlexMa: setenvif example added
    – regilero
    Nov 14, 2013 at 8:52
1

You can also do it with mod_security:

http://static.askapache.com/httpd/mod_security/doc/modsecurity-manual.html#N107EE

LogFormat "%h %l %u %t \"%r\" %>s %{mod_security-body}n

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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