Setting a trace id in nginx load balancer

前端 未结 4 764
臣服心动
臣服心动 2021-01-30 11:13

I\'m using nginx as a load balancer in front of several upstream app servers and I want to set a trace id to use to correlate requests with the app server logs. What\'s the bes

4条回答
  •  無奈伤痛
    2021-01-30 11:41

    nginx 1.11.0 added the new variable $request_id which is a unique identifier, so you can do something like:

       location / {
          proxy_pass http://upstream;
          proxy_set_header X-Request-Id $request_id;
       }
    

    See reference at http://nginx.org/en/docs/http/ngx_http_core_module.html#var_request_id

提交回复
热议问题