Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get the content-length (response header) in apache logs?

I would like Apache to show the response header length (here 90). Instead it shows some 'weird' values that are also client-dependent.

tail /var/log/apache2/access.log

xx.xx.xx.xx - - [16/Oct/2021:11:07:44 +0000] "POST /api/user HTTP/1.1" 200 796 "https://yy/login/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36 OPR/79.0.4143.72"

Inspect Elements

HTTP/1.1 200 OK
Date: Sat, 16 Oct 2021 11:07:44 GMT
Server: Apache/2.4.41 (Ubuntu)
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 90
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
like image 417
2WFR Avatar asked Nov 20 '25 19:11

2WFR


1 Answers

Found the solution :

in /etc/apache2/apache2.conf, the LogFormat directives have to be changed as follows: %b instead of %O.

And now the access.log reports 90 as expected.

This is also discussed here (comment by Jeff Pucket): https://askubuntu.com/questions/264042/what-is-the-default-apache2-log-format-and-where-is-defined-such-default and it looks like this is Ubuntu specific.

like image 85
2WFR Avatar answered Nov 23 '25 08:11

2WFR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!