Configure Caddy using the Caddyfile syntax.
The Caddyfile uses a simple syntax to define how Caddy handles requests.
The Caddyfile uses a simple, readable syntax to define how Caddy handles requests. Each block defines configuration for a domain or path.
``` example.com {
reverse_proxy localhost:8080
} ```
This proxies requests for example.com to localhost:8080.
``` example.com {
reverse_proxy localhost:8080 {
header_up Host {host}
header_up X-Real-IP {remote}
header_up X-Forwarded-For {remote}
header_up X-Forwarded-Proto {scheme}
}
} ```
These headers pass original request information to the backend.
``` example.com {
reverse_proxy localhost:8080
header {
X-Content-Type-Options nosniff
X-Frame-Options SAMEORIGIN
X-XSS-Protection "1; mode=block"
Referrer-Policy strict-origin-when-cross-origin
}
} ```
These headers improve security for your applications.
``` example.com, www.example.com {
reverse_proxy localhost:8080
} ```
This handles both the root domain and www subdomain.
``` api.example.com {
reverse_proxy api-service:3000
}
blog.example.com {
reverse_proxy blog-service:8080
} ```
Each subdomain can proxy to different services.