Connect to backend based on protocol used by client in frontend

Hello,

I want know if it’s possible to connect to the backend server based on the protocol which was used in the frontend.

So for example a client requests the page with http://page.com i want to set the backend port 80 for the backend server and use HTTP as well. When the client connects with HTTPS, the backend should also be requested with SSL port 443.

It’s probably working with two different backends for ex. be_http and be_https but maybe there is a solution with only one backend and some kind of a port variable ?

Thanks in advance!

If you don’t specify a destination port on the backend server, the destination port on the frontend is used. This is for tcp mode, of course.

So:

defaults
 mode tcp

frontend front
 bind :80
 bind :443
 default_backend back

backend back
 server s1 192.168.1.5

Health checking the backend then means specifying the port used for health checks via check port, for example:

backend back
 server s1 192.168.1.5 check port 80

Just don’t set the port with the classic server s1 192.168.1.5:80

Thanks for the answer.

Unfortunately I have another frontend for an external service which listens on port 2400 and uses the same backends as my main one.

If a request now comes through the frontend with port 2400 it uses the same port on the backend server which is not open in the firewall and cannot be opened.

Maybe if there is solution to rewrite the port inside the frontend from 2400 to port 80 / 443 it would work but since the tcp connection is already established i guess not.

You can put:

http-request set-dst-port int(80)

in that frontend, to set the port for this manually.

Amazing! It worked.

1 Like