Quick Verdict (TL;DR)
- Why SSE streaming freezes in production: Reverse proxies buffer response chunks to optimize packet size—so your FastAPI, Ollama, or vLLM token stream sits blank for 20 seconds and then dumps the entire paragraph at once.
- The 3-line Caddy v2 fix: Add
flush_interval -1,response_header_timeout 300s, andstream_timeout 30mon your streaming/webhookhandleblock, and keepencode gzipoutside that route. - Best hosting pairing: Run this Docker + Caddy v2 stack on a flat-rate ~$6–$9/mo Hostinger VPS alongside self-hosted n8n, or skip reverse-proxy ops entirely with managed HTTPS on Railway.
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.
Side-by-Side Comparison
| 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) |
The 3 Hidden Proxy Defaults That Break AI Apps
- Response Buffering: Proxies wait to fill an internal memory buffer before flushing bytes to the browser. For
text/event-stream(SSE) LLM outputs, that destroys perceived latency. - Short Upstream Header Timeouts (30–60s): Reasoning models and multi-step n8n AI agent webhooks frequently take 45–120 seconds before emitting their first response byte—tripping default
504errors. - Gzip Compression Pooling: Enabling global
encode gzip zstdon an SSE route causes the compressor to wait for enough bytes to build a compression dictionary, stalling individual tokens.
The 25-Line Production 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 } } } } Docker Compose Integration (Avoid the Certificate Rate-Limit Trap)
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.
Zero-Downtime Config Reloads & SSE Verification
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.
Keep Your VPS Focused on Core AI Infrastructure
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.
Who Should Choose What?
- Choose Caddy v2 + Docker on **Hostinger VPS** if you self-host streaming LLMs, FastAPI AI agents, or n8n webhooks and want automatic HTTPS, zero-buffering SSE, and flat sub-$10/month hosting.
- Choose **Railway** if you want managed edge HTTPS and instant Git-push deploys without writing a
Caddyfileor managing Ubuntu firewalls. - Pair either backend with **Systeme.io** when you need automated email onboarding and sales funnels without maintaining extra frontend containers.
Frequently Asked Questions
Why does Caddy buffer Server-Sent Events (SSE) from LLM APIs?
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.
What timeout should I set in Caddy for slow AI agent webhooks?
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.
Does gzip compression break LLM streaming in Caddy?
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.
How do I reload Caddy in Docker without disconnecting active users?
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
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.
