Routing to a specific machine

Hello, I want to know how I can route traffic from a domain to a specific local machine. The idea is that I have two machines under the same public ip and I want to access the first machine with for example “pc1.example.com” and the second machine with “pc2.example.com”. How do I setup the config of HAproxy.

If I didn’t misunderstand the question, this is quite a basic scenario in HAproxy. A simple solution to start off building on would be as per following:

Define Frontend: This section listens for incoming traffic on a specific port (usually port 80 for HTTP or 443 for HTTPS).

frontend http_front
    bind *:80
    acl host_pc1 hdr(host) pc1.example.com
    acl host_pc2 hdr(host) pc2.example.com
    use_backend pc1_backend if host_pc1
    use_backend pc2_backend if host_pc2

Define Backends: Here, you specify the local machines that will handle the requests:

backend pc1_backend
    server pc1 192.168.1.2:80 check

backend pc2_backend
    server pc2 192.168.1.3:80 check

Despite this solution is as simple as that, it’s not recommended by many in favour of more complex ones. However, each of them is still based on the fact that the frontend needs to dispatch the request to one of the multiple defined backends.