-
Notifications
You must be signed in to change notification settings - Fork 885
Run Caddy as a daemon
Error404 edited this page May 9, 2021
·
1 revision
Manually install Caddy as a service on Linux with these instructions.
Requirements:
-
caddy
binary that you built with naïve fork of Caddy forwardproxy -
systemctl --version
>= 232 -
sudo
privileges
Make Caddy executable and move caddy binary into your path, and place your Caddyfile under /etc/caddy/
$ chmod +x caddy
$ mv caddy /usr/bin/
$ mkdir /etc/caddy
$ mv Caddyfile /etc/caddy/
Test if it works:
$ /usr/bin/caddy run --config /etc/caddy/Caddyfile
Create unique Linux group and user for caddy:
$ groupadd --system caddy
$ useradd --system \
--gid caddy \
--create-home \
--home-dir /var/lib/caddy \
--shell /usr/sbin/nologin \
--comment "Caddy web server" \
caddy
Next, create caddy.service
under /etc/systemd/system/
with the following contents:
[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target
[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
Double-check the ExecStart
and ExecReload
directives. Make sure the binary's location and command-line arguments are correct for your installation. Change it according to your setup.
After saving the service file, we can now start the caddy service with systemd:
$ systemctl daemon-reload
$ systemctl enable caddy
$ systemctl start caddy
Check the current status:
$ systemctl status caddy
Reload caddy with changed config file:
$ systemctl reload caddy