This site is for tech Q&A. Please keep your posts focused on the subject at hand.

Ask one question at a time. Don't conflate multiple problems into a single question.

Make sure to include all relevant information in your posts. Try to avoid linking to external sites.

Links to documentation are fine, but in addition you should also quote the relevant parts in your posts.

0 votes

We are running Nginx in a reverse proxy configuration, and I need to trace requests end-to-end. With version 1.11 Nginx introduced a new variable $request_id, but unfortunately we're still using version 1.10, so a config check reports

nginx: [emerg] unknown "request_id" variable
nginx: configuration file /etc/nginx/nginx.conf test failed

Can I use something else instead?

in Sysadmin
by (125)
3 20 38
edit history

Please log in or register to answer this question.

1 Answer

0 votes

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.

edited by
by (125)
3 20 38
edit history