add unique id to requests forwarded from nginx reverse proxy

情到浓时终转凉″ 提交于 2019-12-10 22:47:18

问题


We are running nginx as a reverse proxy that forwards requests to a Clojure application running Compojure, a library that wraps around Jetty and provides our application with the ability to service web requests.

We currently capture logs generated by both nginx and the Clojure application (via log4j to syslog). We are unable, however, to match an entry in the nginx log to an entry in the syslog output of the Clojure application.

We need to figure out a way to modify the request sent upstream to the Clojure app to include some kind of ID. This could be an integer, UUID, whatever.

Do you have any suggestions as to how best to accomplish this?

Thanks for your help!


回答1:


Compojure is written on ring and ring has middleware :)

you would write a middleware called with-uuid that adds the UUID to the request map on the way in and to the reply on the way out.




回答2:


Of course the best approach would be an nginx module, duplicating the functionality of apache's mod_unique_id.

There doesn't seem to be one yet. Here's a patch that wants to graduate to a module someday.:

http://mailman.nginx.org/pipermail/nginx-devel/2011-June/001015.html



来源:https://stackoverflow.com/questions/4038559/add-unique-id-to-requests-forwarded-from-nginx-reverse-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!