Nginx, Caddy 2, Traefik v3 & Cloudflare Tunnel Config Matrix Generator
Generate syntax-checked reverse-proxy and zero-trust tunnel configurations across Nginx 1.27, Caddy 2.8, Traefik v3.2, and Cloudflared simultaneously. Eliminates 60-second Server-Sent Events (SSE) buffering drops, Cloudflare 100-second HTTP 524 timeouts, WebSocket 101 upgrade resets, and Docker 0.0.0.0 UFW firewall bypasses locally in your browser.
1. Target Workload & Security Guards
2. Production Config Output (4 Engines)
/etc/nginx/conf.d/n8n_sse.confPanel A · Hardened Nginx Reverse-Proxy Block
# /etc/nginx/conf.d/n8n_sse.conf (Nginx 1.26+ / HTTP2 + Unbuffered MCP SSE)
map $http_upgrade $connection_upgrade {
default upgrade;
'' "";
}
limit_req_zone $binary_remote_addr zone=gfl_app_limit:10m rate=60r/s;
upstream gfl_n8n_sse {
server 127.0.0.1:5678 max_fails=3 fail_timeout=10s;
keepalive 64;
keepalive_requests 10000;
keepalive_timeout 65s;
}
server {
listen 443 ssl;
http2 on;
server_name n8n.example.com;
ssl_certificate /etc/letsencrypt/live/n8n.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/n8n.example.com/privkey.pem;
ssl_protocols TLSv1.3;
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
client_max_body_size 16m;
location / {
limit_req zone=gfl_app_limit burst=120 nodelay;
proxy_pass http://gfl_n8n_sse;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_buffering off;
proxy_cache off;
gzip off;
chunked_transfer_encoding on;
add_header X-Accel-Buffering "no" always;
proxy_connect_timeout 10s;
proxy_send_timeout 3600s;
proxy_read_timeout 3600s;
proxy_buffer_size 16k;
proxy_buffers 8 16k;
}
}
Panel B · Companion Docker Compose Upstream Binding
# docker-compose.yml (UFW-safe 127.0.0.1 loopback port publish + proxy env)
services:
n8n:
image: n8nio/n8n:latest
restart: unless-stopped
ports:
- "127.0.0.1:5678:5678"
environment:
- N8N_HOST=n8n.example.com
- N8N_PROTOCOL=https
- N8N_PROXY_HOPS=1
- N8N_SECURE_COOKIE=true
- WEBHOOK_URL=https://n8n.example.com/
Panel C · Live Verification (curl -i -N & Socket Audit)
# 1. Validate Nginx syntax & confirm upstream binds strictly to 127.0.0.1:5678
sudo nginx -t && sudo systemctl reload nginx
sudo ss -tulpn | grep ':5678'
# 2. Verify TLS 1.3 handshake + ALPN h2 negotiation
openssl s_client -connect n8n.example.com:443 -tls1_3 -alpn h2 </dev/null 2>/dev/null | grep -E "Protocol|Cipher|ALPN"
# 3. Stream live unbuffered SSE frames (confirm X-Accel-Buffering: no & <50ms first chunk)
curl -i -N --http2 -H "Accept: text/event-stream" --max-time 15 https://n8n.example.com/mcp/sse
proxy_buffering off; proxy_read_timeout 3600s; keepalive 64;
reverse_proxy 127.0.0.1:5678 { flush_interval -1 }
entryPoints.websecure.transport.respondingTimeouts.readTimeout=3600s
disableChunkedEncoding: false; keepAliveTimeout: 3600s (+15s ping)
Empirical Reverse-Proxy & Tunnel Benchmark Matrix (Nginx vs Caddy 2 vs Traefik v3 vs Cloudflared)
Measured on GearFlow Lab isolated loopback topologies (127.0.0.1 container bindings, TLS 1.3 ECDSA P-256, oha -n 2000 -c 100 HTTP/2 concurrency, and docker stats --no-stream Resident Set Size checks).
| Proxy / Tunnel Engine | Container RSS (Idle / c=100) | TLS 1.3 Latency (p50 / p99) | HTTP/2 Throughput | SSE & WebSocket Idle Behavior | Config & Reload Model |
|---|---|---|---|---|---|
| Nginx 1.27 nginx:1.27-alpine |
18.0 MiB / 36.0 MiB |
1.85 ms / 14.20 ms |
24,800+ req/sRequires keepalive 64 + Connection "" |
Buffers chunks (408.7 ms TTFT) & drops at 60s unless proxy_buffering off + proxy_read_timeout 3600s. |
Explicit nginx.conf / stream {}; zero-drop worker reload via nginx -t && nginx -s reload. |
| Caddy 2.8 caddy:2.8-alpine |
14.24 MiB / 33.97 MiB |
2.21 ms / 39.30 ms |
10,034 req/s (H2)13,133 req/s over HTTP/1.1 |
Auto-flushes text/event-stream; add flush_interval -1 for raw NDJSON/Ollama token streams; native WSS. |
Minimal Caddyfile + built-in ACME TLS; 0.31s zero-downtime API reload (caddy reload). |
| Traefik v3.2 traefik:v3.2 |
23.48 MiB / 66.50 MiB |
3.24 ms / 35.11 ms |
20,083 req/s (H2)18,651 WSS frames/s (50 clients) |
Streams SSE & RFC 6455 WSS natively; tune respondingTimeouts.readTimeout so idle streams do not close early. |
Dynamic Docker label discovery; returns 404 immediately when container stops; enforce chmod 600 acme.json. |
| Cloudflare Tunnel cloudflared:2024.11+ |
54.0 MiB / 66.0 MiB |
+12 to 28 ms / 68.0 msIncludes nearest Cloudflare PoP hop |
Edge-proxied QUIC / H2 Zero inbound WAN ports (80/443 closed) |
Hard 100.0s edge HTTP 524 cutoff on silent connections; emit : keepalive SSE frames every 15s. |
Outbound-only QUIC tunnel via config.yml; verify rules offline with cloudflared tunnel ingress validate. |
Why Default Reverse-Proxy Blocks Break SSE, WebSockets, and Host Firewalls
Standard HTTP reverse-proxy defaults assume short request-response lifecycles. In Nginx ngx_http_proxy_module, response buffering is enabled by default and proxy_read_timeout defaults to 60 seconds, which traps small text/event-stream frames in memory buffers (increasing first-token latency from 24.8 ms to 408.7 ms in our lab) and severs idle MCP or LLM connections at the 60-second mark. For Layer-4 PostgreSQL and PgBouncer multiplexing, routing belongs inside Nginx ngx_stream_core_module rather than an http {} server block.
Modern Go proxies simplify TLS lifecycle management while introducing distinct streaming semantics. Caddy 2 reverse_proxy automatically provisions Let's Encrypt or ZeroSSL certificates and honors flush_interval -1 for low-latency streaming, whereas Traefik v3 entrypoint transport timeouts govern long-lived SSE and WebSocket connections discovered from Docker container labels. When exposing services without opening inbound WAN ports via Cloudflare Tunnel origin configuration, remember that Cloudflare's edge still enforces a 100-second read timeout (HTTP 524) unless your upstream emits periodic SSE heartbeat frames.
Regardless of which proxy terminates TLS, publishing a backend container with -p 5678:5678 binds 0.0.0.0:5678 and writes Docker iptables NAT rules ahead of UFW, exposing unauthenticated databases or Ollama APIs directly on the public interface. Binding container ports to 127.0.0.1:PORT:PORT (or sharing an internal Docker bridge network) closes that bypass permanently.
Reverse-Proxy & Tunnel Configuration Matrix FAQ
Why do n8n MCP SSE and Ollama streams drop at 60s behind Nginx or 100s behind Cloudflare Tunnel?
Nginx closes upstream connections after 60 seconds of silence (proxy_read_timeout 60s) and buffers small SSE frames unless proxy_buffering off and X-Accel-Buffering: no are set. Behind Cloudflare Tunnel, Cloudflare's edge proxy enforces a 100-second idle read limit (HTTP 524) even when keepAliveTimeout is raised locally, so long-running workflows must emit an SSE comment heartbeat every 15 seconds or return HTTP 202 Accepted asynchronously.
Why must Docker upstream containers bind to 127.0.0.1 instead of 0.0.0.0 when running on Ubuntu with UFW?
Publishing ports: ["5678:5678"] tells Docker Engine to insert DNAT rules in the Linux kernel nat PREROUTING chain before UFW's filter INPUT rules evaluate incoming packets. Changing the host publish syntax to 127.0.0.1:5678:5678 restricts raw TCP access to the local loopback interface so every external client must pass through your TLS reverse proxy and rate limiter.
When should I choose Nginx, Caddy 2, Traefik v3, or Cloudflared for self-hosted AI and DevOps stacks?
Choose Nginx 1.27 for maximum HTTP/2 request throughput, fine-grained limit_req_zone burst protection, FastCGI WordPress pools, and Layer-4 TCP/TLS stream routing. Choose Caddy 2 for the lowest configuration overhead and instant automatic HTTPS. Choose Traefik v3 when containers scale dynamically via Docker Compose labels. Choose Cloudflared when running behind CGNAT or strict inbound firewalls where ports 80 and 443 cannot be opened.
Pair Your Proxy Config With Verified Sizing & Triage Guides
Paste raw Nginx 502/504/499, Cloudflare 524, Traefik ACME, or UFW logs locally in under 5 ms.
Side-by-side container memory, cold-start latency, and broken-upstream HTTP 502 vs 404 tests.
Full reproduction of buffered SSE stalls and zero-drop location routing for MCP endpoints.
Audit nat/PREROUTING exposure and lock down container ports behind your reverse proxy.
Why keepalive 32 requires HTTP/1.1 plus empty Connection headers and Uvicorn 65s alignment.
Sum container RSS across n8n, Postgres, PgBouncer, Redis, OpenObserve, Nginx, and Cloudflared.