Apache Access Log records incoming HTTP requests to the server, and the CustomLog directive defines what is kept in the log. The following is an example HTTP request, CustomLog directive, and the corresponding log that it captures:
GET /apache/log-post?field01=value01&field02=value02 HTTP/1.1 Host: simplified.guide Content-Type: application/x-www-form-urlencoded
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
52.46.36.182 - - [30/Jan/2020:18:04:53 +0000] "GET /apache/log-post?field01=value01&field02=value02 HTTP/1.1" 200 13375 "-" "Amazon CloudFront"
The above CustomLog directive is sufficient if you're only logging GET requests, as, by default, Apache can log the HTTP request headers. 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.
$ sudo a2enmod dump_io #Ubuntu and Debian Enabling module dump_io. To activate the new configuration, you need to run: systemctl restart apache2 $ sudo a2enmod dumpio # SUSE
Options | Debian, Ubuntu | openSUSE and SLES | Fedora Core, CentOS, RHEL | macOS | homebrew | xampp |
---|---|---|---|---|---|---|
a2enmod support | yes | yes | no | no | no | no |
Modules to install | none | |||||
Module name | n/a | dumpio | ||||
Loadmodule directive | n/a | LoadModule dumpio_module <module_locations>/mod_dumpio.so |
$ sudo vi /etc/apache2/httpd.conf
Configure the below steps/lines in a VirtualHost directive to apply the logging configuration only to a specific VirtualHost configuration.
DumpIOInput On DumpIOOutput On
LogLevel dumpio:trace7
Related: How to manage Apache service
$ curl -XPOST --data "field01=value01&field02=value02" 127.0.0.1
$ sudo grep field01 /var/log/apache2/error.log [Sun Feb 02 01:46:13.062838 2020] [dumpio:trace7] [pid 21080] mod_dumpio.c(100): [client 127.0.0.1:47386] mod_dumpio: dumpio_in (data-HEAP): field01=value01&field02=value02
Comment anonymously. Login not required.