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 {
handle /v1/chat/completions* {
reverse_proxy http://ai-backend:8000 {
flush_interval -1
stream_timeout 30m
transport http {
response_header_timeout 300s
keepalive 3m
}
header_up X-Forwarded-For {remote_host}
header_up X-Forwarded-Proto {scheme}
}
}
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. Off 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
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.