This repo is about learning Caddy web server.
The official documentation can be found here: https://caddyserver.com/docs
- easy to setup and use
- https by default with no conguration needed (from let's encrypt)
- HTTP/2, IPv6, Markdown, WebSockets, gzip, basic auth, templates and more right out of the box
- build for designer, bloggers and developers
-
Download Caddy: https://caddyserver.com/download
-
Create a config which is namend
Caddyfile
and add the following minimal configlocalhost:8080 { root www }
-
Put your web assets into the
www
folder -
Start Caddy with
caddy
. If your config file is not in the same directory as you are you can use it via theconf
option like-conf="DIR_TO_CONF/Caddyfile"
To start the example servers within this repo (configuration and caddy itself) hit
# Mac
./bin/mac/caddy
# Windwos
bin\win64\caddy.exe
# Linux
./bin/linux64/caddy
All configuration is made in the Caddyfile
. There are a lot of build in features but some need to be added to the binary.
You have to re-download Caddy with the additional features if you want to use one of them, it cant be added afterwards.
The following features are all build-in. If a feature must be added to the binary it is marked with an A
in the documentation.
Ext allows you to make clearer URLs by allowing to leave out the file extension in the URL
ext .html .md
With the example above the user can now go to the hello.html
file with either /hello.html
or /hello
.
You can map HTTP errors to specific pages
errors {
404 notfound.html
503 serviceunavail.html
}
Caddy can render markdown files out of the box
markdown
The markdown files can also be served with custom css and js.
You can protect files and directories with simple basic auth
basicauth user password {
/secret
}
Caddy will log every request when you add the log tag.
log / logs/access.log
Theres an easy syntax to format the logs to your needs.
gzip enabled gzip support if the client supprots it.
gzip
Caddy can server as proxy
proxy /hypem hypem.com:80 {
without /hypem
}
This will proxy all /hypem
requests to hypem.com
. If we would not add the without
tag the request would be proxied with the host in the URL.
Example URL: http://localhost:8080/hypem/playlist/popular/3day/json/1/data.js
Load balancer is part of the proxy feature. There are some policy features available as well as health checks to only server to working servers.
localhost:2016 {
proxy / localhost:8080 localhost:8081 {
policy random
}
}
- Run Caddy as service with systemd
- Install caddy via command line with https://getcaddy.com/
- Caddy FAQ
Made with ❤️ at SinnerSchrader