Hey all,
I’ve been struggling to get Run Apache, Nginx & HAProxy on Same Server (Ubuntu 20.04 in my case) on my home network for a week now. I’ve tried following the tutorial but I get stuck on the part:
“You can define a default back end with:” default_backend nginx
and " We will use SNI header in the HTTPS request to redirect to the correct back end. For example, if Nginx is serving domain1.com
and Apache is serving domain2.com
, then you add the following two lines."
because I followed other two tutorials Install NextCloud on Ubuntu 20.04 with Nginx (LEMP Stack) and Install NextCloud on Ubuntu 20.04 with Apache (LAMP Stack)
Both are working when I try to access them via nextcloud.myhomedomain.net and phpmyadmin.myhomedomain.net.
After I follow this tutorial and move them to 127.0.0.2:443 and 127.0.0.1:443 and when I try to access them from outside my network I can access nextcloud.myhomedomain.net and I get the correct LE certificate and it works, but for phpmyadmin.myhomedomain.net I’m getting an error of invalid certificate and it is from HAProxy for my ubuntu.myhomedomain.net located in /etc/haproxy/haproxy.pem
I guess, what I’m unable to find online is how to have HAProxy point to each individual domain because I do not need load balancing.
If anyone can shed some light on this I would really appreciate it!
Here’s what I have in /etc/haproxy/haproxy.cfg
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
stats timeout 30s
user haproxy
group haproxy
daemon
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# See: https://ssl-config.mozilla.org/#server=haproxy&server-version=2.0.3&config=intermediate
ssl-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-SHA384
ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets
tune.ssl.default-dh-param 2048
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
frontend http
bind 192.168.1.115:80
mode http
redirect scheme https code 301
frontend https
bind 192.168.1.115:443
mode tcp
tcp-request inspect-delay 5s
tcp-request content accept if { req_ssl_hello_type 1 }
backend phpmyadmin
mode tcp
option ssl-hello-chk
server phpmyadmin 127.0.0.1:555 check
backend nextcloud
mode tcp
option ssl-hello-chk
server nextcloud 127.0.0.2:444 check
listen stats
bind 192.168.1.115:443 ssl crt /etc/haproxy/haproxy.pem
stats enable # enable statistics reports
stats hide-version # Hide the version of HAProxy
stats refresh 30s # HAProxy refresh time
stats show-node # Shows the hostname of the node
stats auth haadmin:P@ssword # Enforce Basic authentication for Stats page
stats uri /stats # Statistics URL
server phpmyadmin 127.0.0.1:555 send-proxy-v2 check
server nextcloud 127.0.0.2:444 send-proxy-v2 check