2

Is there any way to create a custom log file, that allows to see which requests were handled in the same keep-alive session?

I'd like to create some logs and to estimate how often new sessions are created and what typical live times a keep alive session has in some given scenarios.

If possible I wouldn't like to create debug logs for this but just add one item more per log line for each request.

gelonida
  • 205
  • 3
  • 11

1 Answers1

3

There are $connection and $connection_requests variables that you could use in custom log_format. Just a sample:

log_format connections '[$time_local] "$request" $connection $connection_requests';

server {
    access_log /var/log/nginx/connections.log connection;
    ...
}
Alexey Ten
  • 7,922
  • 31
  • 35