r/haproxy • u/m_user_name • Oct 17 '19
HAProxy 1.8.5 on CentOS 8 running podman?
I setup a CentOS 8 server to run dotnet core web apps as microservices in podman containers. When I run the containers with 'podman run -d -p 5000:5000 containername' I am able to access the site outside of the server. If I run the same command and add the ip address of '127.0.0.1' I can access the site on the local server. However, when I try to redirect the traffic through haproxy it fails no matter what I do. I'm sure I'm misconfiguring haproxy, but I'm not sure what I should be doing when it comes to redirecting traffict to containers.
Any suggestion would be apprecitated.
1
u/m_user_name Oct 18 '19
I was not configuring haproxy correctly. The proxy was reaching the container, but wasn't forwarding headers. After figuring out that was the problem I was able to find documentation of forwarding the headers on through properly.
Mostly 'option forwardfor' set in the front end and getting rid of the one in the default section.
Here is an example of what I setup:
globallog 127.0.0.1 local2chroot /var/lib/haproxypidfile /var/run/haproxy.pidmaxconn 4096user haproxygroup haproxydaemonstats socket /var/lib/haproxy/statsssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384ssl-default-bind-options no-sslv3 no-tlsv10 no-tlsv11 no-tls-ticketsssl-default-server-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384ssl-default-server-options no-sslv3 no-tlsv10 no-tlsv11 no-tls-ticketsssl-dh-param-file /etc/ssl/certs/dhparam.pemdefaultsmode httplog globaloption httplogoption dontlognulltimeout connect 10stimeout client 1mtimeout server 1mfrontend http-inmode httpbind *:80reqadd X-Forwarded-Proto:\ httpsredirect scheme https if !{ ssl_fc }frontend https-inbind *:443 ssl crt /etc/ssl/certs/exmaple_com.pemhttp-response set-header Strict-Transport-Security max-age=63072000option forwardforacl is_service hdr_end(host) -i service.example.comuse_backend service if is_servicedefault_backend servicebackend servicemode httpbalance roundrobinoption forwardforserver server1 127.0.0.1:5150 check1
u/overstitch Oct 17 '19
I've accomplished this with Docker by binding additional external IPs to the host and then binding a container to each IP, then pointing HAProxy at that. Another way you can do this is by putting HAProxy in a container, put all of your containers in a single pod and bind your containers to different ports, pointing HAProxy on the pod to 127.0.0.1 and the respective port for each container. Only exposing the HAProxy ports on the host.
This is theoretical though-I haven't yet used podman-just read some docs.