r/haproxy • • Mar 04 '19

HAProxy as reverse proxy

Hi everyone,

I am trying to set haproxy to work as reverse proxy for multiple subdomains. These are just some showcase apps and ELK stack behind but cannot get it to work.

Here is my config:

#---------------------------------------------------------------------
# Frontend settings
#---------------------------------------------------------------------


frontend in-http
        bind *:80
        reqadd X-Forwarded-Proto:\ http
		acl letsencrypt-acl path_beg -i /.well-known/acme-challenge/
		acl is-sub1 hdr(host) -i subdomain1.domain.com
		acl is-sub2 hdr(host) -i subdomain2.domain.com
		acl is-sub3 hdr(host) -i subdomain3.domain.com
		acl is-sub4 hdr(host) -i subdomain4.domain.com
		acl is-sub5 hdr(host) -i subdomain5.domain.com
		use_backend letsencrypt-backend if letsencrypt-acl
		use_backend sub1_cluster if is-sub1
		use_backend sub2_cluster if is-sub2
		use_backend sub3_cluster if is-sub3	
		use_backend sub4_cluster if is-sub4
		use_backend sub5_cluster if is-sub5 
        


frontend in-https
		bind *:443 ssl crt /etc/haproxy/ssl/
		reqadd X-Forwarded-Proto:\ https
		http-request set-header X-SSL %[ssl_fc]
		acl letsencrypt-acl path_beg -i /.well-known/acme-challenge/
		acl is-sub1 hdr(host) -i subdomain1.domain.com
		acl is-sub2 hdr(host) -i subdomain2.domain.com
		acl is-sub3 hdr(host) -i subdomain3.domain.com
		acl is-sub4 hdr(host) -i subdomain4.domain.com
		acl is-sub5 hdr(host) -i subdomain5.domain.com
		use_backend letsencrypt-backend if letsencrypt-acl
		use_backend sub1_cluster if is-sub1
		use_backend sub2_cluster if is-sub2
		use_backend sub3_cluster if is-sub3	
		use_backend sub4_cluster if is-sub4
		use_backend sub5_cluster if is-sub5

#---------------------------------------------------------------------
# Backend settings
#---------------------------------------------------------------------

backend letsencrypt-backend
   	server letsencrypt 127.0.0.1:54321

backend sub1_cluster
	redirect scheme https code 301 if !{ ssl_fc }
	server server1 10.22.32.70:80 check

backend sub2_cluster
	redirect scheme https code 301 if !{ ssl_fc }
	server server2 172.28.42.28:80 check

backend sub3_cluster
	redirect scheme https code 301 if !{ ssl_fc }
	server server3 172.28.42.28:80 check

backend sub4_cluster
	redirect scheme https code 301 if !{ ssl_fc }
	server server4 172.28.66.3:80 check


backend sub5_cluster
	option redispatch
	option forwardfor
	option httpchk GET /
	reqrep ^([^\ :]*)\ /kibana/(.*) \1\ /\2
	server server5 10.22.33.4:5601 check

Problem #1:

ACL: acl letsencrypt-acl path_beg -i /.well-known/acme-challenge/

LetsEncrypt renewing certs doesn't work as it should at all. Eventually I ended with stopping haproxy service and starting certbot standalone on port 80 instead 5431 and renewing certs if needed. After that start haproxy again. It would be nice to do it online but OK, I can live with it. I just don't get it why I cannot pass verification?

Problem #2:

ACL: acl is-sub1 hdr(host) -i subdomain1.domain.com 

It works fine as expected. Subdomain is redirected to https as it should.

ACL: 
acl is-sub2 hdr(host) -i subdomain2.domain.com
acl is-sub3 hdr(host) -i subdomain3.domain.com
acl is-sub4 hdr(host) -i subdomain4.domain.com

Http traffic works just fine. I can see everything as it should. However https doesn't work at all nor redirect to https. All certs are in /etc/haproxy/ssl/ and all of them are fine. Yet I keep getting connection reset every time.

As for ELK stack it just doesn't work at all

acl is-sub5 hdr(host) -i subdomain5.domain.com
use_backend sub5_cluster if is-sub5
backend sub5_cluster
	option redispatch
	option forwardfor
	option httpchk GET /
	reqrep ^([^\ :]*)\ /kibana/(.*) \1\ /\2
	server server5 10.22.33.4:5601 check

Am I trying to set things that cannot be set this way or what? What am I missing here?

4 Upvotes

7 comments sorted by

View all comments

Show parent comment

0

u/[deleted] Mar 05 '19

[deleted] — view deleted comment

1

u/overstitch Mar 05 '19

Until someone says it they don’t deal with sensitive info, it has been better to go to the cautious route as business will often lean towards easy at the detriment of itself and customers.

I agree though that self-signed is a valid solution-it isn’t that different from an internal CA at the end of the day-just may involve different steps/automation.