You can define a custom variable in your vhost where you combine other variables to a unique string, for instance:
set $my_req_id $connection-$connection_requests-$msec;
$connection
: serial number of the connection
$connection_requests
: current number of requests made through the connection
$msec
: current time in seconds with milliseconds resolution
Then set a custom header using that variable:
add_header X-Request-Id $my_req_id; # for responses sent to the client
location / {
proxy_set_header X-Request-Id $my_req_id; # for requests sent to upstream backend
}
Reload or restart Nginx and you should see the new header appear in requests/responses.