Spec-Zone.ru › Caddy

Caddyfile Quick-start

Create a new text file named Caddyfile (no extension).

The first thing to type in a Caddyfile is your site's address:

localhost

If the HTTP and HTTPS ports (80 and 443, respectively) are privileged ports on your OS, you will either need to run with elevated privileges or use higher ports. To gain permission, run as root with sudo -E or use sudo setcap cap_net_bind_service=+ep $(which caddy). Alternatively, to use higher ports, just change the address to something like localhost:2080 and change the HTTP port using the http_port Caddyfile option.

Then hit enter and type what you want it to do, so it looks like this:

localhostrespond "Hello, world!"

Save this and run Caddy from the same folder that contains your Caddyfile:

caddy start

You will probably be asked for your password, because Caddy serves all sites -- even local ones -- over HTTPS by default. (The password prompt should only happen the first time!)

For local HTTPS, Caddy automatically generates certificates and unique private keys for you. The root certificate is added to your system's trust store, which is why the password prompt is necessary. It allows you to develop locally over HTTPS without certificate errors.

(If you get permission errors, you may need to run with elevated privileges or choose a port higher than 1023.)

Either open your browser to localhost or curl it:

curl https://localhost
Hello, world!

You can define multiple sites in a Caddyfile by wrapping them in curly braces { }. Change your Caddyfile to be:

localhost {
	respond "Hello, world!"
}
localhost:2016 {
	respond "Goodbye, world!"
}

You can give Caddy the updated configuration two ways, either with the API directly:

curl localhost:2019/load \
	-H "Content-Type: text/caddyfile" \
	--data-binary @Caddyfile

or with the reload command, which does the same API request for you:

caddy reload

Try out your new "goodbye" endpoint in your browser or with curl to make sure it works:

curl https://localhost:2016
Goodbye, world!

When you are done with Caddy, make sure to stop it:

caddy stop

Further reading

  • Caddyfile concepts
  • Directives
  • Common patterns

© 2015-2025 Matthew Holt and The Caddy Authors
Licensed under the Apache License 2.0.
Caddy is a registered trademark of Stack Holdings GmbH.
https://caddyserver.com/docs/quick-starts/caddyfile

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API