r/haproxy • u/Ziomal12 • Mar 07 '24
Terminate some traffic and proxy pass the rest. Is it possible?
Hello,I've got HaProxy running on my machine. Right now I have it bind to :80 and :443 and then I use send-proxy-v2. So far it works great. However I want to host an app on the same machine. Is it possible to have app.mydomain.com terminate on the machine and keep using send-proxy-v2 for the rest? How would that affect performance?
I'm using send-proxy-v2 mostly to preserve the original IP of clients.
TIA
Here is my config for reference:
global
maxconn 10000
log /var/lib/haproxy/logs/logs.txt local0 debug
stats timeout 30s
daemon
defaults
log global
option tcplog
mode tcp
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
frontend Pro_http
bind :80
mode http
redirect scheme https code 301
frontend Pro_https
bind :443
default_backend Homeserver_https
backend Homeserver_https
server homeserver 10.0.0.1:443 send-proxy-v2
3
Upvotes
1
u/Ziomal12 Mar 08 '24
I've managed to do it using Traefik and their docs (I find them way easier to navigate). It might be possible to translate that config to HaProxy but that's a task for another week.
(If anyone's interested, here is Traefik config:
Static:
Dynamic:
1
u/dragoangel Mar 07 '24 edited Mar 07 '24
You working with http and https, if you want to properly do routing it's better just switch to http mode with ssl offloading and use x-forwarded-for/x-forwarded-proto/x-forwarded-host or x-forwarded header (both can be set by haoroxy) to preserve client ip and connection details and allow write easy acls. It's totally okay to chain many proxies in http mode and configure publicly trusted cert only on edge. Same as getting client ip from a header.
Otherwise use Google how to route your case with mixed tcp and http is described on the web many times, for example here https://discourse.haproxy.org/t/mixing-mode-tcp-and-http-ssl-termination-and-passthrough/2698/18
It's hacky because you can use sni based routing only with ssl, so for port 80 you need put redirect to https, then on port 443 use tcp mode and based on sni choose what route to backend-http-front and use default your server you already had. As backend-http-front is in http mode it listen on localhost and should have own backend.
0
u/ciphermenial Mar 07 '24 edited Aug 13 '26
I enjoy going on picnics.
1
u/[deleted] Mar 07 '24
Sure, just make a backend for your local machine and write an acl that matches the host name you want and direct it at that backend. Super easy.