Table of Contents

Caddyfile Configuration

Configure Caddy using the Caddyfile syntax.

The Caddyfile uses a simple syntax to define how Caddy handles requests.

Overview

The Caddyfile uses a simple, readable syntax to define how Caddy handles requests. Each block defines configuration for a domain or path.

Basic Reverse Proxy

``` example.com {

  reverse_proxy localhost:8080

} ```

This proxies requests for example.com to localhost:8080.

With Headers

``` 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.

With Security Headers

``` 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.

Multiple Domains

``` example.com, www.example.com {

  reverse_proxy localhost:8080

} ```

This handles both the root domain and www subdomain.

Subdomains

``` api.example.com {

  reverse_proxy api-service:3000

}

blog.example.com {

  reverse_proxy blog-service:8080

} ```

Each subdomain can proxy to different services.

References

See Also

Last updated: 2026-06-19