我正在尝试使用 HAProxy 将位于原始路径中的服务器名称重写为 Host 标头,并保存该名称以用于use_backend
逻辑。例如,我希望proxy.my.host/server-1/some-request
将其重写为server-1.internal/some-request
,然后使用 选择server-1
的后端use_backend
。
frontend my_proxy
...
# grab the server name from the request path
http-request set-var(req.server_name) path,lower # how do I trim /some-request from here?
# strip /server-N from the path
http-request replace-path ^(/server-[0-9]+) /
# change the host header to server-N.internal
http-request set-header Host var(req.server_name).internal
# select the backend
use_backend %[var(req.server_name)]
backend server-1
...
...
对于这种事情,这通常是正确的方法吗?