Guidelines

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
15 views
15 views

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 General by (265) 7

Your answer

Preview

Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
By submitting this post you agree to our Terms & Conditions.
To avoid this verification in future, please log in or register.

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.

by (265) 7
edited 2 days ago by
...