How to Configure HAProxy for Docker-based Nextcloud AIO
Purpose
Set upConfigure HAProxy on pfSense to terminate SSL and properlysecurely reversereverse-proxy proxypublic HTTPS traffic to an internal Docker Nextcloud AIO (Apacheserver containerbehind onyour port 11000), based on our hands-on configuration today.firewall.
1. InstallHAProxy HAProxyPackage Installation on UbuntupfSense
go sudoto:
apthaproxy 2. BasicCreate SSL Certificate (or Import)
In pfSense:
nextcloud.mydomain.com).
3. HAProxy Configuration FileSettings
WeGo editedto Services → HAProxy and configure:
Global Settings
Frontend (Public Side)
Name: frontend-https Bind address: WAN Address (or "any") Port: 443 Type: SSL Offloading (HTTPS) SSL Certificate: [Select imported Let's Encrypt or custom cert]
Actions:
Host Header = nextcloud.mydomain.com
Action: Use Backend: backend-nextcloud
Optional:
4. HAProxy configurationBackend at:(Internal Docker Host)
Name: backend-nextcloud Mode: HTTP (or HTTPS if you terminate SSL at the container) Server list: Name: nextcloud-docker Address: 192.168.100.19 Port: 11000 Health Check Method: HTTP-OPTIONS
Important Backend Options:
5. Nextcloud Trusted Proxy Configuration
On the Nextcloud server, we modified the trusted proxies:
sudo docker exec -it nextcloud-aio-nextcloud bash cd /var/www/html/config nano /etc/haproxy/haproxy.cfgconfig.php
Global
Add Settings:or verify these lines inside config.php:
global'trusted_proxies' log=> ['192.168.100.1'], 'overwritehost' => 'nextcloud.mydomain.com', 'overwriteprotocol' => 'https', 'overwrite.cli.url' => 'https:/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 ca-base /etc/ssl/certs crt-base /etc/ssl/private ssl-default-bind-ciphers PROFILE=SYSTEM ssl-default-bind-options no-sslv3 Defaults:
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 3. Frontend Configuration
HTTP - Redirect to HTTPS:
frontend http-in bind *:80 redirect scheme https code 301 if !{ ssl_fc } HTTPS - SSL Termination:
frontend https-in bind *:443 ssl crt /etc/ssl/private/nextcloud.mydomain.pem mode http option forwardfor http-request set-header X-Forwarded-Proto https if { ssl_fc } default_backend nextcloud_backendcom',
Note: Replace
with yourmydomain.pem192.168.100.1actualpfSenseSSLLANcombinedIPcertificateif(fullchain + private key).different.
4. Backend Configuration
Forward traffic internally to the Apache container at port 11000:
backend nextcloud_backend server nextcloud 127.0.0.1:11000 check
This points to Nextcloud AIO Apache container's internal port 11000 (NOT container IP, just localhost).
5. Certificates
We manually combined the certificate like this:
cat fullchain.pem privkey.pem > /etc/ssl/private/mydomain.pem Permissions were secured:
sudo chmod 600 /etc/ssl/private/mydomain.pem 6. Restart andDocker EnableNextcloud HAProxyContainer
sudo systemctldocker restart haproxy sudo systemctl enable haproxynextcloud-aio-nextcloud 7. Verify Setup
https://yourdomain.com✅ Summary
- pfSense HAProxy listens on
80WANand 443.