Human: I need to set up a reverse proxy for my Next.js app. Should I use Nginx or Caddy? Assistant: For a Next.js app, I'd recommend Caddy. Here's why: **Automatic HTTPS** - Caddy handles Let's Encrypt certificates automatically. No certbot, no cron jobs, no renewal scripts. With Nginx you need to set up certbot separately and manage renewal. **Simpler config** - A complete Caddy reverse proxy config is 3 lines: ``` your-domain.com { reverse_proxy localhost:3000 } ``` The equivalent Nginx config is 20-30 lines with server blocks, SSL parameters, proxy headers, and upstream definitions. **HTTP/2 and HTTP/3 by default** - Caddy enables modern protocols automatically. Nginx requires explicit configuration. The main reason to choose Nginx instead: if you need very high concurrency (100K+ connections) or your team already knows Nginx well. Human: That's convincing. Can you give me a production-ready Caddyfile for Next.js with WebSocket support? Assistant: Here's a production Caddyfile for Next.js: ``` your-domain.com { reverse_proxy localhost:3000 { header_up X-Forwarded-For {remote_host} header_up X-Forwarded-Proto {scheme} header_up Host {host} } header { X-Content-Type-Options nosniff X-Frame-Options DENY Referrer-Policy strict-origin-when-cross-origin -Server } encode gzip zstd log { output file /var/log/caddy/access.log } } ``` WebSocket support works automatically with Caddy's reverse_proxy - no special configuration needed. The `header_up` directives pass the real client IP and protocol to Next.js. Human: Perfect, thanks. Saved this to wr.fi for the team.
Conversation about choosing a reverse proxy for Next.js. Demonstrates wr.fi's chat transcript parsing.
Log in to leave a comment.