Caddy 部署实践

Caddy

Caddy Web服务器QUIC部署

QUIC在微博中的落地思考

Examples for using Caddy Web Server

本站开启支持 QUIC 的方法与配置

使用caddy配合nginx支持QUIC

1
wget https://github.com/mholt/caddy/releases/download/v0.10.12/caddy_v0.10.12_linux_amd64.tar.gz
1
2
3
tar xf caddy_v0.10.12_linux_amd64.tar.gz

mv caddy /usr/local/bin/

/usr/local/bin/caddy -quic -log stdout -agree=true -conf=/data/caddy/Caddyfile -root=/var/tmp –port=32457

mkdir -p /data/caddy/log/

1
2
3
4
5
6
7
8
vim /data/caddy/Caddyfile

ovwane.com:444 {
tls /data/ssl/ovwane.com/ovwane.com_rsa_fullchain.cer /data/ssl/ovwane.com/ovwane.com_rsa.key
root /data/www/ovwane.com/public
gzip
log /data/caddy/log/ovwane.com.log
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
vim /usr/lib/systemd/system/caddy.service

[Unit]
Description=Caddy HTTP/2 web server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service

[Service]
Restart=on-abnormal

; User and group the process will run as.
;User=caddy
;Group=caddy

; Letsencrypt-issued certificates will be written to this directory.
Environment=CADDYPATH=/data/caddy

; Always set "-root" to something safe in case it gets forgotten in the Caddyfile.
ExecStart=/usr/local/bin/caddy -quic -log stdout -agree=true -conf=/data/caddy/Caddyfile -root=/var/tmp
ExecReload=/bin/kill -USR1 $MAINPID

; Use graceful shutdown with a reasonable timeout
KillMode=mixed
KillSignal=SIGQUIT
TimeoutStopSec=5s

; Limit the number of file descriptors; see `man systemd.exec` for more limit settings.
LimitNOFILE=1048576
; Unmodified caddy is not expected to use more than that.
LimitNPROC=512

; Use private /tmp and /var/tmp, which are discarded after caddy stops.
PrivateTmp=true
; Use a minimal /dev (May bring additional security if switched to 'true', but it may not work on Raspberry Pi's or other devices, so it has been disabled in this dist.)
PrivateDevices=false
; Hide /home, /root, and /run/user. Nobody will steal your SSH-keys.
ProtectHome=true
; Make /usr, /boot, /etc and possibly some more folders read-only.
ProtectSystem=full
; … except /etc/ssl/caddy, because we want Letsencrypt-certificates there.
; This merely retains r/w access rights, it does not add any new. Must still be writable on the host!
ReadWriteDirectories=/data/caddy

; The following additional security directives only work with systemd v229 or later.
; They further restrict privileges that can be gained by caddy. Uncomment if you like.
; Note that you may have to add capabilities required by any plugins in use.
;CapabilityBoundingSet=CAP_NET_BIND_SERVICE
;AmbientCapabilities=CAP_NET_BIND_SERVICE
;NoNewPrivileges=true

[Install]
WantedBy=multi-user.target
1
2
3
4
systemctl enable caddy.service
systemctl start caddy.service
systemctl stop caddy.service
systemctl status caddy.service
1
netstat -lnp --inet6 | grep -F caddy

日志自动切分

vim /etc/logrotate.d/caddy

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/data/caddy/log/*.log {
su root root
daily
rotate 5
missingok
notifempty
sharedscripts
dateext
postrotate
if [ -f /var/run/caddy.pid ]; then
kill -USR1 `cat /var/run/caddy.pid`
fi
endscript
}

手动执行

1
/usr/sbin/logrotate -f /etc/logrotate.d/caddy

×

纯属好玩

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

文章目录
,