Skip to main content

Using the Admin API

The Caddy Admin API allows you to manage your server at runtime without restarts. It provides full control over configuration, certificates, and server state.

Admin Endpoint

By default, the admin API listens on localhost:2019:

Custom Listen Address

Change the admin endpoint address:
The admin endpoint can be configured via the CADDY_ADMIN environment variable, which defaults to localhost:2019.

Disable Admin API

Disabling the admin API makes runtime changes impossible. You’ll need to restart Caddy to apply new configurations.

Configuration Management

Get Current Config

Retrieve the entire configuration:

Load Configuration

Replace the entire configuration:

Update Specific Path

Modify a specific configuration path:

PATCH vs POST vs PUT

  • GET - Retrieve configuration
  • POST - Add to an array or create if doesn’t exist
  • PUT - Create new value (fails if exists)
  • PATCH - Update existing value (fails if doesn’t exist)
  • DELETE - Remove configuration

Using @id for Easier Access

Identify configuration objects with @id for cleaner API paths:

Common Operations

Add a New Site

Update Upstream Servers

Reload Certificates

Trigger certificate renewal:

Security

Origin Enforcement

Protect against DNS rebinding attacks:

Remote Admin (TLS)

Secure the admin endpoint with mutual TLS:
Remote admin requires identity management to be configured. The endpoint uses mutual TLS for authentication.

Debugging Endpoints

Caddy exposes several debugging endpoints:

pprof Profiling

Metrics

Graceful Shutdown

Stop Caddy gracefully:

ETag Support

The API supports ETags to prevent concurrent modifications:

Complete Example

Manage a site lifecycle via API:

Best Practices

The admin API returns detailed error messages in JSON format when operations fail. Always check the response body for debugging information.

Troubleshooting

Connection Refused

Permission Denied

Ensure origin/host headers match allowed origins:

Invalid JSON

Validate JSON before posting: