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.

4
  • 1
  • @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 7:40
  • you could post an answer yourself and accept it
    – Alexey Ten
    May 25 '20 at 8:15
  • 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
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;
    ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.