Caddy Installation
Build Caddy
- Download the lastest version of Caddy.
1 2
| wget https://github.com/caddyserver/caddy/releases/download/v2.0.0-rc.3/caddy_2.0.0-rc.3_linux_amd64.tar.gz
|
- Unzip
1
| tar zxvf caddy_2.0.0-rc.3_linux_amd64.tar.gz
|
- Move execution file to
/usr/bin/
Install Caddy
- Create the group
1
| sudo groupadd --system caddy
|
- Create a new user
1 2 3 4 5 6 7
| sudo useradd --system \ --gid caddy \ --create-home \ --home-dir /var/lib/caddy \ --shell /usr/sbin/nologin \ --comment "Caddy web server" \ caddy
|
Log
- Create folder to save logs
1
| sudo mkdir /var/log/caddy
|
- Modified folder authority
1
| sudo chown -R caddy:caddy /var/log/caddy
|
Create caddyfile
Caddy reads its configuration from a file called Caddyfile, stored under /etc/caddy.
1 2 3 4 5 6 7 8 9
| your_domain { root * /var/www encode gzip file_server log { output file /var/log/caddy/service_access.log } }
|
Service
/etc/systemd/system
create a folder file caddy.service
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| [Unit] Description=Caddy Documentation=https://caddyserver.com/docs/ After=network.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
|
Caddy system command
- Reload the systemd daemon
1
| sudo systemctl daemon-reload
|
- Automatic start caddy
1
| sudo systemctl enable caddy
|
- Active caddy
1
| sudo systemctl start caddy
|
- Caddy status
1
| sudo systemctl status caddy
|
- Reload caddy
1
| sudo systemctl reload caddy
|
- Stop caddy
1
| sudo systemctl stop caddy
|
Functions
Log
Enables access logging; the log directive can still be used in v2, but all logs are structured, encoded as JSON, by default.
1 2 3 4
| log { output file access.log format single_field common_log }
|
Reverse_proxy
1
| reverse_proxy localhost:9005
|
SSL certificate
Caddy root content is /var/lib/caddy/
, where SSL certificate is at
1
| /var/lib/caddy/.local/share/caddy/certificates
|
Force update SSL certificate, need delete SSL certificate, and restart Caddy
1 2 3
| cd /var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory rm -rf example.com systemctl restart caddy
|