Request Id for logging purposes

Francis Daly francis at
Wed Feb 4 19:15:32 UTC 2015

On Wed, Feb 04, 2015 at 11:07:13AM -0800, Igal @ wrote:

Hi there,

> I want to be able to identify requests by a unique id. 
> I'm able to do this in the location section:
>         proxy_set_header    X-Request-Id       
> $pid-$msec-$remote_addr-$request_length;
> but I want instead to set it to a variable, e.g. in the http section:
>     set $request_id $pid-$msec-$remote_addr-$request_length;    ## does
> this work?


It can be at "server" level, though.

>     add_header      X-Request-Id    $request_id;    ## I don't see it in
> the response headers

You probably were not running with this configuration.

> can it work?

With "set" at server{} level, yes.

All of the normal nginx configuration directive rules apply.

Francis Daly        francis at

More information about the nginx mailing list