Answer the question
In order to leave comments, you need to log in
How to configure logging of slow requests in nginx?
There is a server with Ubuntu 14.04, it has Nginx 1.9.4 and various services with REST API that are called from the outside world through Nginx. How can I set up logging in Nginx so that only slow requests are logged? For example, log all requests that are processed for more than 2 seconds, including the connection timeout to REST services?
PS I would like to know how to configure exactly Nginx (not to write any parsers).
Answer the question
In order to leave comments, you need to log in
In general, the solution is this:
1. Install the nginx-extras package.
2. In the location configuration we write:
set $logging 0;
log_by_lua '
if tonumber(ngx.var.upstream_response_time) >= 2 then
ngx.var.logging=1
end;
';
access_log /path/to/log format if=$logging
if ($upstream_response_time !~* "[0-3]\.[0-9][0-9][0-9]" { access_log /file format; }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question