Get Caddy up and running in minutes with this quick start guide. You’ll learn how to serve static files and set up a reverse proxy with automatic HTTPS.
Prerequisites
Before you begin, make sure you have Caddy installed. See the installation guide if you haven’t installed Caddy yet.
Verify your installation:
Serve a Static Site
Create a simple HTML file
Create an index.html file in a new directory: mkdir mysite
cd mysite
echo '<h1>Hello from Caddy!</h1>' > index.html
Start Caddy
Run Caddy with the file server: Your site is now available at http://localhost:2015
Use a Caddyfile
For more control, create a Caddyfile in your site directory:
Then start Caddy:
Caddy automatically looks for a Caddyfile in the current directory when you run caddy run without specifying a config.
Enable Automatic HTTPS
To enable automatic HTTPS for a real domain:
For automatic HTTPS to work:
You must own the domain
DNS must point to your server
Ports 80 and 443 must be open
Caddy must be publicly accessible
Reverse Proxy
Here’s how to proxy requests to a backend application:
localhost
reverse_proxy localhost:8080
This forwards all requests to your application running on port 8080.
With Path-Based Routing
localhost
handle /api/* {
reverse_proxy localhost:8080
}
handle {
file_server
}
Common Caddyfile Patterns
Static Site with Compression
example.com
encode gzip
file_server
SPA (Single Page Application)
example.com
root * /var/www/myapp
try_files {path} /index.html
file_server
example.com
reverse_proxy localhost:3000 {
header_up X-Real-IP {remote_host}
}
Multiple Sites
site1.com {
root * /var/www/site1
file_server
}
site2.com {
reverse_proxy localhost:8080
}
Production Operations
Start Caddy as a service
Use caddy start to run in the background:
Reload configuration
After changing your Caddyfile: This performs a zero-downtime reload.
Using the Admin API
Caddy’s admin API runs on localhost:2019 by default.
Get current config
curl localhost:2019/config/
Load a new config
curl localhost:2019/load \
-H "Content-Type: application/json" \
-d @config.json
Next Steps
Core Concepts Learn about Caddy’s architecture and module system
Caddyfile Master the Caddyfile configuration format
Reverse Proxy Deep dive into reverse proxy configuration
CLI Reference Explore all Caddy commands