How to log the start time of a request in Nginx

Solution 1:

I know this is an old question, but I think it deserves an update, for nginx>1.2.5 (as of July 2017 nginx stable is 1.13) this is now trivial

In the log use

start_time="$msec"

Or to add a header:

add_header X-Request-Start $msec

or for a proxy

proxy_set_header X-Request-Start $msec

Solution 2:

Well, there is a patch for nginx (https://gist.github.com/rkbodenner/318681#comment-610856) that exposes request start time as a variable.

I think it could be useful in your case.

Solution 3:

You can write $msec and $request_time to the log and use $msec - $request_time as the start time when parsing.