Caddy
Caddy is a fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS. It provides an extensible platform which can be used as a HTTP server, reverse proxy, or static file server. Caddy and its extensions are written in Go.
Installation
USE flags
USE flags for www-servers/caddy Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
+filecaps
|
Use Linux file capabilities to control privilege rather than set*id (this is orthogonal to USE=caps which uses capabilities at runtime e.g. libcap) |
events-handlers-exec
|
Builds a module which lets user exec command on Caddy events https://caddyserver.com/docs/modules/events.handlers.exec https://caddyserver.com/docs/caddyfile/options#event-options |
security
|
Authentication, Authorization, and Accounting. LDAP, OAuth, SAML, MFA, 2FA, JWT etc.. https://caddyserver.com/docs/modules/security https://github.com/greenpau/caddy-security |
Emerge
root #
emerge --ask www-servers/caddy
Configuration
Caddy's default config file when using the Gentoo package is /etc/caddy/Caddyfile.
Simple text response
To configure a basic HTTP server that responds with simple text, using a Caddyfile [1] is the easiest way to get started. The config for this looks like:
localhost {
respond "Hello, Gentoo!"
}
Using a domain
For a more real-world setup where you have a domain you would like to host a web server on, the config will look like the following:
example.com {
root * /var/www/example.com # the root of the website
tls webmaster@example.com # email on the HTTPS certificate
file_server # enables a static file server
}
Reverse proxies
Caddy allows you to use a reverse proxy to allow HTTPS connections over the Internet without having port conflicts. For reverse proxying a web server listening on port 8080
using Caddy, the following config will allow you to do so:
sub.example.com {
reverse_proxy :8080
}
Usage
Services
OpenRC
To start Caddy using OpenRC, run
root #
rc-service caddy start
and to have it run on boot, run
root #
rc-update add caddy default
Systemd
To start Caddy on Systemd, run
root #
systemctl start caddy
and to have it start on boot, run
root #
systemctl enable caddy
Command line usage
Using a specified config file
To start Caddy with a config file that is not /etc/caddy/Caddyfile, run
user $
caddy run --config /path/to/Caddyfile
Reloading
Caddy config can be reloaded in a zero-downtime fashion. To reload Caddy from the command-line, you can run
user $
caddy reload
or for reloading the service:
root #
rc-service caddy reload
root #
systemctl reload caddy
See also
- Apache — an efficient, extensible web server. It is one of the most popular web servers used the Internet.
- Nginx — a robust, small, high performance web server and reverse proxy server.
References
- ↑ The Caddyfile — Caddy Documentation, caddyserver. Retrieved on May 24, 2024