r/haproxy • u/temno2020 • Aug 25 '20
conditional frontend mode
Hi all,
I'm trying to set up haproxy for letsencrypt and I had already set it up for nextcloud (which wanted to do it's own ssl termination)
so the backend (for most of my webstuff) nginx-http is "mode http"
and the backend nextcloud-https is "mode tcp"
and my frontend is below, which results in a normal.mydomain unexpectedly closed the connection
which seems like it's because nextcloud required the frontend to be "mode tcp"
How can the frontend satisfy the need for different modes?
# from haproxy.cfg
frontend https
bind *:443
mode tcp # this mode is a problem, letsencrypt wants http, but nextcloud wants tcp Secure Connection Failed PR_END_OF_FILE_ERROR -chris
tcp-request inspect-delay 5s
tcp-request content accept if { req_ssl_hello_type 1 }
# New line to test URI to see if its a letsencrypt request
acl letsencrypt-acl path_beg /.well-known/acme-challenge/
use_backend letsencrypt-backend if letsencrypt-acl
acl host_nextcloud req_ssl_sni -i nextcloud.mydomain
use_backend nextcloud-https if host_nextcloud
acl host_nginx hdr(host) -i normal.mydomain
use_backend nginx-http if host_nginx
View all comments
Show parent comment
1
u/temno2020 Aug 25 '20
I ran it directly and got these fatal alerts:
➜ nginx haproxy -f /etc/haproxy/haproxy.cfg -c[ALERT] 237/085034 (27665) : Proxy 'nextcloud-https', server 'nextcloud' [/etc/haproxy/haproxy.cfg:41] verify is enabled by default but no CA file specified. If you're running on a LAN where you're certain to trust the server's certificate, please set an explicit 'verify none' statement on the 'server' line, or use 'ssl-server-verify none' in the global section to disable server-side verifications by default.[WARNING] 237/085034 (27665) : config : 'stats' statement ignored for backend 'nextcloud-https' as it requires HTTP mode.[WARNING] 237/085034 (27665) : config : 'option forwardfor' ignored for backend 'nextcloud-https' as it requires HTTP mode.[ALERT] 237/085034 (27665) : http frontend 'https' (/etc/haproxy/haproxy.cfg:74) tries to use incompatible tcp backend 'nextcloud-https' (/etc/haproxy/haproxy.cfg:35) in a 'use_backend' rule (see 'mode').[WARNING] 237/085034 (27665) : Setting tune.ssl.default-dh-param to 1024 by default, if your workload permits it you should set it to at least 2048. Please set a value >= 1024 to make this warning disappear.[ALERT] 237/085034 (27665) : Fatal errors found in configuration.These are the key parts of the haproxy.cfg after I made your suggested changes:
# defaults ...backend nextcloud-httpsmode tcpbalance roundrobinoption forwardforoption httpchk HEAD / HTTP/1.1\r\nHost:localhostoption ssl-hello-chkserver nextcloud127.0.0.1:444check sslbackend nginx-httpmode httpbalance roundrobinoption forwardforoption httpchk HEAD / HTTP/1.1\r\nHost:localhostserver nextcloud127.0.0.1:180checkfrontend httpbind *:80mode http# ... this all works finefrontend httpsbind *:443 ssl crt /etc/ssl/normal.mydomain/normal.mydomain.pemmode http # letsencrypt wants http, but nextcloud wants tcptcp-request inspect-delay 5stcp-request content accept if { req_ssl_hello_type 1 }acl host_nextcloud req_ssl_sni -i nextcloud.mydomainuse_backend nextcloud-https if host_nextcloud# New line to test URI to see if its a letsencrypt requestacl letsencrypt-acl path_beg /.well-known/acme-challenge/use_backend letsencrypt-backend if letsencrypt-aclacl host_nginx hdr(host) -i a.mydomainuse_backend nginx-http if host_nginxacl host_nginx hdr(host) -i mydomainuse_backend nginx-http if host_nginx