2WFR
2WFR

Reputation: 145

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

Upvotes: 3

Views: 1437

Answers (1)

2WFR
2WFR

Reputation: 145

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.

Upvotes: 1

Related Questions