Why Your Streaming LLM & AI Webhooks Buffer Behind Docker Reverse Proxies (And the 25-Line Caddy v2 Fix) A developer published a 25-line Caddy v2 configuration for running streaming LLM and AI agent webhook backends behind Docker reverse proxies, addressing SSE token buffering and 504 Gateway Timeout failures. The setup uses flush_interval -1, stream_timeout 30m, and a 300s response_header_timeout on a dedicated handle block for streaming routes, while keeping gzip/zstd compression off those paths. It also recommends persistent /data and /config Docker volumes to avoid re-requesting Let's Encrypt certificates on every restart. flush interval -1 , response header timeout 300s , and stream timeout 30m on your streaming/webhook handle block, and keep encode gzip outside that route. Your streaming AI chat or multi-step agent webhook works smoothly on http://localhost:8000 . Then you put Docker and a reverse proxy in front of it for HTTPS—and suddenly token-by-token SSE streaming stalls, or long reasoning chains crash with 504 Gateway Timeout . Below is the exact 25-line Caddy v2 production configuration we deploy in 2026 for streaming LLMs, FastAPI AI workers, and n8n webhooks—plus zero-downtime reloads. | Reverse Proxy / Edge Option | Auto Let's Encrypt TLS | SSE Streaming Config Effort | Zero-Downtime Reload | Monthly Infra Cost | |---|---|---|---|---| | Caddy v2 in Docker on Hostinger VPS | Built-in automatic | 3 directives flush interval -1 + timeouts | caddy reload instant | ~$6.49–$8.79/mo flat VPS | | Nginx + Certbot on VPS | Manual Certbot cron | Requires proxy buffering off , X-Accel-Buffering , chunked headers | nginx -s reload | ~$6.49–$8.79/mo flat VPS | | Managed Edge on Railway | Built-in automatic | Zero config managed proxy | Managed rolling deploys | ~$15–$45+/mo 24/7 metered | text/event-stream SSE LLM outputs, that destroys perceived latency. 504 errors. encode gzip zstd on an SSE route causes the compressor to wait for enough bytes to build a compression dictionary, stalling individual tokens. Caddyfile Copy-Paste Ready Split your streaming/webhook paths into a dedicated handle block so normal static/JSON routes still benefit from fast defaults while AI routes stream immediately: { email ops@yourdomain.com } ai.yourdomain.com { Dedicated non-buffered route for LLM SSE streams & slow AI agent webhooks handle /v1/chat/completions { reverse proxy http://ai-backend:8000 { Flush every SSE chunk immediately disables response buffering flush interval -1 stream timeout 30m transport http { Wait up to 5 minutes for first token / multi-step agent reply response header timeout 300s keepalive 3m } header up X-Forwarded-For {remote host} header up X-Forwarded-Proto {scheme} } } Standard API / UI routes safe to compress handle { encode zstd gzip reverse proxy http://ai-backend:8000 { transport http { response header timeout 60s } } } } Always persist /data and /config in named Docker volumes. If you rebuild Caddy without a persistent /data volume, every container restart requests a brand-new Let's Encrypt certificate—hitting Let's Encrypt's weekly rate limit within an hour. services: caddy: image: caddy:2-alpine restart: unless-stopped mem limit: 256m ports: - "80:80" - "443:443" volumes: - ./Caddyfile:/etc/caddy/Caddyfile:ro - caddy data:/data - caddy config:/config networks: - ai-net volumes: caddy data: caddy config: networks: ai-net: driver: bridge Note that inside Docker, Caddy connects to your upstream service via the Docker Compose service name http://ai-backend:8000 or http://n8n-main:5678 , never http://localhost:8000 . When you update routes or timeouts in Caddyfile , reload Caddy in-place without dropping active AI streams or TLS sockets: docker compose exec caddy caddy validate --config /etc/caddy/Caddyfile docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile Verify unbuffered streaming immediately using curl -N --no-buffer : curl -N -H "Accept: text/event-stream" https://ai.yourdomain.com/v1/chat/completions If tokens print line-by-line immediately instead of waiting until the stream closes, your proxy is production-ready. Run Caddy + Docker on Hostinger VPS for your AI APIs, RAG backends, and n8n webhooks—and avoid self-hosting marketing landing pages or email funnels on the same box. Offloading lead capture, checkout funnels, and automated email sequences to Systeme.io $0 Free / $27/mo Startup keeps your VPS footprint minimal and isolates customer-facing marketing uptime from backend deployments. Reverse proxies buffer responses by default to optimize packet framing. Setting flush interval -1 inside Caddy's reverse proxy block disables response buffering so every SSE token chunk streams to the client immediately. Set response header timeout 300s inside transport http to allow up to 5 minutes for initial LLM prefill or multi-step agent execution, and set stream timeout 30m for lengthy streaming generations. It can delay token delivery if compression buffers chunks before flushing. Isolating your SSE/streaming endpoint into its own handle block without encode gzip ensures instant token-by-token delivery. Run docker compose exec caddy caddy validate --config /etc/caddy/Caddyfile followed by docker compose exec caddy caddy reload --config /etc/caddy/Caddyfile . Caddy applies the new config gracefully with zero downtime. Open-Source Starter Repo: Grab the ready-to-deploy Docker Compose + Caddy + PostgreSQL + Redis stack on GitHub: https://github.com/Soph1yzzz/n8n-ai-agent-docker-stack https://github.com/Soph1yzzz/n8n-ai-agent-docker-stack Question for builders: What is your current monthly bill or biggest production bottleneck running AI agents or webhooks—and are you self-hosting or staying on managed cloud? Drop your stack in the comments. Full benchmarks, cost tables, and updated 2026 blueprints on AgentStack https://soph1yzzz.github.io/agentstack-hq/posts/docker-caddy-reverse-proxy-ai-webhooks-2026/ .