Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to log POST data in Apache?

Imagine you have a site API that accepts data in the form of GET requests with parameters, or as POST requests (say, with standard url-encoded, &-separated POST data). If you want to log and analyze API calls, the GET requests will be easy, because they will be in the apache log. Is there a simple way to get the POST data in the apache log as well?

(Of course we could log the POST data explicitly in the application, but I'd like to have an configuration-level way that let me not worry about it in code.)

like image 565
Kevin Weil Avatar asked Jun 13 '09 04:06

Kevin Weil


People also ask

Does Apache log post data?

POST data is sent in the request's body, so Apache can't log POST requests by default. You can log POST request details by using dumpio module for Apache, which allows logging of HTTP request body.

What is the typical log file size per 10k requests in an Apache Web server?

Log Rotation The access log file typically grows 1 MB or more per 10,000 requests.


2 Answers

Use Apache's mod_dumpio. Be careful for obvious reasons.

Note that mod_dumpio stops logging binary payloads at the first null character. For example a multipart/form-data upload of a gzip'd file will probably only show the first few bytes with mod_dumpio.

Also note that Apache might not mention this module in httpd.conf even when it's present in the /modules folder. Just manually adding LoadModule will work fine.

like image 155
Spider Avatar answered Oct 08 '22 20:10

Spider


You can install mod_security and put in /etc/modsecurity/modsecurity.conf:

SecRuleEngine On SecAuditEngine On SecAuditLog /var/log/apache2/modsec_audit.log SecRequestBodyAccess on SecAuditLogParts ABIJDFHZ 
like image 25
Jeroen Vermeulen - MageHost Avatar answered Oct 08 '22 22:10

Jeroen Vermeulen - MageHost