Caddy

From Gentoo Wiki
Jump to:navigation Jump to:search
This article is a stub. Please help out by expanding it - how to get started.

Caddy is a fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS.

Installation

USE flags

USE flags for www-servers/caddy Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

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
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)
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

Note
Caddy's default config file when using the Gentoo package and OpenRC service is /etc/caddy/Caddyfile

Simple text response

To configure a basic HTTP server that responds with simple text, using a Caddyfile is the easiest way to get started. The config for this looks like:

FILE Caddyfile
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:

FILE Caddyfile
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:

FILE Caddyfile
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

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