大网数据广告活动
服务器运维问答

Can HAProxy generate a UUID based unique connection id?

· 52CE 我爱测

I have an HAProxy load balancer that I would like to use to tag requests with a unique id (X-Unique-ID header) so that I can correlate events between logs in multiple systems. HAProxy has a feature for doing this with the unique-…

问题原文

原帖链接 · zaphoyd · CC BY-SA 4.0

I have an HAProxy load balancer that I would like to use to tag requests with a unique id (X-Unique-ID header) so that I can correlate events between logs in multiple systems.

HAProxy has a feature for doing this with the unique-id-format directive. The documentation explains that this uses only the syntax from the logging system and goes on to suggest that you use things like the client and server ip addresses, timestamps, etc to build something that is likely to be unique.

I am wondering if it is possible to generate a random (version 4) UUID (or something similar) for each request rather than generating one with potentially sensitive client information like IP address and request time.

已采纳解答

原帖链接 · micmax93 · CC BY-SA 4.0

Starting from HAProxy 2.0 uuid() function is available.
So this should do exactly what you need:

unique-id-format %[uuid()]
unique-id-header X-Unique-ID

One advantage to using unique-id-header instead of http-request set-header, is that you can set it in defaults section.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-04-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。