我在tcp模式下使用haproxy。 我有一个前端可以监听几个端口:
frontend front mode tcp bind *:20000 bind *:20001 ... default_backend back
还有一个后端在不改变端口的情况下转发这些请求:
backend back server myserver server.host.com check port 20000 server anotherServer another.host.com check port 20000 server mybackup backup.host backup.host.com check port 20000 backup # some other useful backend logic, like logging # which I don't want to repeat a bunch of times
因为我们支持一些传统的API,所以我们需要接受一些旧的,低层的端口并重新映射它们。 例如,我想接受端口200并将其重新映射到20000到20001等。
我希望有一个前端指令来改变端口,就像你可能会在http模式下做一个header一样,但是我找不到。 将不得不放弃我干净的单一后端?
如果我是你,我会去使用2个后端。
如果坚持,则可以使用use-server <server> if <condition>选项并testingdst_port 。
就像: use-server bla20001 if dst_port 201或类似的东西。
我相信没有好办法做到这一点。 我最终创造了更多的前端和后端。