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
  • 259
  • 3
  • 16
  • 1
    http://nginx.org/en/docs/http/ngx_http_core_module.html#var_connection – Alexey Ten May 25 '20 at 06:32
  • @AlexeyTen thanks a lot. This is the answer. As you sent it as a comment. What do you suggest? I delete the question? You post as answer and I accept? Anything else? – gelonida May 25 '20 at 07:40
  • OK true: might do that next time, but prefer to attribute the points to the one who helped me (except the person doesn't care) – gelonida May 25 '20 at 14:25

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
  • 8,435
  • 1
  • 34
  • 36