VPS指南:安装使用caddy

本文最后更新于:2022年10月4日 晚上

其实这篇文章是紧接着流量监控那一篇

发现使用自动脚本部署流量监控的网页的时候,caddy总是无法启动,所以干脆自己部署网站。要注意的是网站路径是/usr/local/ServerStatus/web

安装caddy

caddy官方安装教程
对于debian系统

1
2
3
4
5
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo apt-key add -
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy

如果在root下运行,删除sudo

1
2
3
4
5
apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | apt-key add -
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
apt update
apt install caddy

使用caddy version来查看是否安装成功

1
2
root@debian:~# caddy version
v2.4.3 h1:Y1FaV2N4WO3rBqxSYA8UZsZTQdN+PwcoOcAiZTM8C0I=

配置caddy

安装好caddy后,在路径/etc/caddy下会自动生成配置文件Caddyfile,我们可以进入该目录然后对文件进行编辑

1
2
cd /etc/caddy
vim Caddyfile

也可以新建文件夹

1
2
3
mkdir caddy
cd caddy
vim Caddyfile

修改配置文件如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
:8888 {
# Set this path to your site's directory.
root * /usr/local/ServerStatus/web

# Enable the static file server.
file_server

# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080

# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:900
encode gzip
}

之后在Caddyfile同文件夹目录下运行caddy start

其他命令:

1
2
3
4
5
caddy help
caddy reload #更新Caddyfile之后重新加载配置文件
caddy stop #停止运行caddy
caddy run #在前台运行caddy
caddy start #在后台运行caddy

官方文档:https://caddyserver.com/docs/command-line


VPS指南:安装使用caddy
https://pawswrite.xyz/posts/16707.html
作者
Rainbow
发布于
2021年6月21日
许可协议