Caddy Local Development Guide
Use Caddy to provide automatic HTTPS and reverse proxy on localhost, forwarding requests to backends like Vite, Node, PHP, etc.
Caddy is a modern web server known for its automatic HTTPS (Let’s Encrypt) and simple Caddyfile configuration. It is commonly used in local development as a reverse proxy, unifying the localhost entry and forwarding to backends like Vite (5173), Laravel (8000), and others.
Typical localhost Scenarios
| Configuration | Effect |
|---|---|
| Reverse proxy to Vite | Browser accesses http://localhost → internally forwards to localhost:5173 |
| Multi-project paths | /api → 3000, / → 5173 |
| Local HTTPS | https://localhost uses Caddy’s built-in local certificate |
Installation
macOS: brew install caddy
Linux: See caddyserver.com/docs/install
Windows: Download exe or use Scoop
Caddyfile Example
Proxy Vite Development Server
:80 {
reverse_proxy localhost:5173
}Start: caddy run or caddy start --config Caddyfile
Access http://localhost to reach the Vite application.
Frontend and Backend Separation
:80 {
handle /api/* {
reverse_proxy localhost:3000
}
handle {
reverse_proxy localhost:5173
}
}Local HTTPS
localhost {
reverse_proxy localhost:4321
}Caddy automatically generates a locally trusted certificate (requires installing Caddy’s root CA: caddy trust).
Comparison with Nginx / Apache
| Item | Caddy | Nginx |
|---|---|---|
| Configuration | Extremely simple Caddyfile | More complex nginx.conf |
| HTTPS | Automatic issuance and renewal | Requires certbot, etc. |
| Ecosystem | Relatively new, local/dev friendly | Widely used in production |
Frequently Asked Questions
Port 80 occupied by Apache/XAMPP
Stop other web services or have Caddy listen on :8080.
WebSocket / HMR failures
Caddy supports WebSocket reverse proxy by default; ensure reverse_proxy points to the correct Vite port.
With Docker
Caddy can be used as the only container exposing 80/443 in a Compose setup.
Summary
Caddy is suitable for unifying the proxy for multiple dev servers on http://localhost, with optional debugging in a secure context using https://localhost; its configuration is simpler than Nginx.