Haproxy remap tcp port with single backend

haproxy

I'm using haproxy in tcp mode. I have a single frontend that listens to several ports:

frontend front
   mode tcp
   bind *:20000
   bind *:20001
   ...
   default_backend back

And a single backend that forwards these requests without changing ports:

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

Because we are supporting some legacy APIs, we need to accept some old, lower level ports and remap them. For example, I want to accept port 200 and remap it to 20000, 201 to 20001, etc.

I was hoping for a frontend directive to change port like you might do for a header in http mode, but I can't find one. Will have have to abandon my nice clean single backend?

Best Answer

I would go about using 2 backends if I were you.

If you insist, you can use the use-server <server> if <condition> option and test dst_port.

Something like: use-server bla20001 if dst_port 201 or something like this.