2

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?

1

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.

  • I wish it were only two backends! There are probably up to 10 ports I will be listening to. Thankfully the haproxy configuration will be created dynamically based on the ports provided in the application configuration, but I was still hoping that the resulting configuration would stay slim. – pduncan Dec 14 '15 at 21:21
  • Did you try the use-server thing? – Florin Asăvoaie Dec 15 '15 at 21:56
  • Nah, I just ended up creating loads of front-ends. – pduncan Jan 4 '16 at 22:06
0

I believe there is no good way to do this. I ended up creating more frontends and backends.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.