Caddy 是一款使用 Go 语言开发的 Web 服务器。其配置更为简洁,并可以自动申请及配置 SSL 证书
系统:Ubuntu 18.04
参考文档:How To Host a Website with Caddy on Ubuntu 16.04
下载安装Caddy(这步仅是安装下Caddy的执行文件),默认是安装到/usr/local/bin/caddy
curl https://getcaddy.com | bash -s personal
注册Caddy服务,可看到文档:systemd Service Unit for Caddy
sudo chown root:root /usr/local/bin/caddy
sudo chmod 755 /usr/local/bin/caddy
# 使其在非root权限下能绑定的到80、443特权端口
sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/caddy
创建用户、用户组以及等相关目录
sudo groupadd -g 33 www-data
sudo useradd \
-g www-data --no-user-group \
--home-dir /var/www --no-create-home \
--shell /usr/sbin/nologin \
--system --uid 33 www-data
下载Caddy配置文件及相关路径
curl -o /etc/caddy/Caddyfile --create-dirs https://raw.githubusercontent.com/halo-dev/halo-common/master/Caddyfile
sudo chown root:root /etc/caddy/Caddyfile
sudo chmod 644 /etc/caddy/Caddyfile
打开Caddyfile
文件可见下述几行基本的信息
https://www.simple.com {
gzip
tls xxxx@xxx.xx
proxy / localhost:port {
transparent
}
}
将https://www.simple.com
改成IP:port或者是网址,xxxx@xxx.xx
改成邮箱用于自动注册证书,port
改成你要的端口
配置SSL存放路径
sudo mkdir /etc/ssl/caddy
sudo chown -R root:www-data /etc/ssl/caddy
sudo chmod 0770 /etc/ssl/caddy
创建一个目录来存储Caddy将托管的文件
sudo cp -R example.com /var/www/
sudo chown -R www-data:www-data /var/www/example.com
sudo chmod -R 555 /var/www/example.com
最后是要配置systemd服务
wget https://raw.githubusercontent.com/caddyserver/caddy/master/dist/init/linux-systemd/caddy.service
sudo cp caddy.service /etc/systemd/system/
sudo chown root:root /etc/systemd/system/caddy.service
sudo chmod 644 /etc/systemd/system/caddy.service
并重新加载systemctl,enable
开启服务,start
启动caddy服务,status
查看状态
sudo systemctl daemon-reload
sudo systemctl enable caddy
sudo systemctl start caddy.service
sudo systemctl status caddy.service
参考资料:
Caddy Debian 9 安装启动
Caddy最容易上手的Web Server-自动化HTTPS一分钟部署网站
本文出自于http://www.bioinfo-scrounger.com转载请注明出处