安装
参考官方文档:https://caddyserver.com/docs/install
配置
配置文件路径/etc/caddy/Caddyfile
基础配置
记得把网站目录的权限赋给caddy
用户
# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.
:2333 {
# Set this path to your site's directory.
root /ulucky/www
# 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:9000
}
# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile
反向代理
:2333 {
reverse_proxy localhost:8000
}
配置go环境和安装xcaddy(如果已经有了可以跳过)
首先确认一下服务器的架构 uname -m
Go 官网:https://go.dev/dl/ 下载对应的版本
解压go的二进制文件
tar -C /usr/local/ -xzf go1.24.0.linux-amd64.tar.gz
编辑shell文件
vim ~/.bashrc
添加环境变量
export PATH=$PATH:/usr/local/go/bin
激活配置文件
source ~/.bashrc
验证
go version
安装xcaddy
github地址:https://github.com/caddyserver/xcaddy
go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
配置环境变量,跟上面Go环境配置一样,增加一行就行
export PATH=$PATH:/root/go/bin
source /root/.bashrc
验证 xcaddy version
以腾讯云为例配置插件
github地址:https://github.com/caddy-dns/tencentcloud
安装插件
xcaddy build --with github.com/caddy-dns/tencentcloud
将新构建的 Caddy 二进制文件替换系统中的 Caddy
# 备份原有的 Caddy
sudo mv /usr/bin/caddy /usr/bin/caddy.backup
# 将新构建的 Caddy 复制到系统目录
sudo cp ./caddy /usr/bin/caddy
全局配置
{
acme_dns tencentcloud {
secret_id ""
secret_key ""
}
}
单独某一个站点配置
tls {
dns tencentcloud {
secret_id "你的ID"
secret_key "你的key"
}
}
记住这里还可以用环境变量,就是把ID和Key配置到环境变量中,然后
env.TENCENTCLOUD_SECRET_ID
这么用,哦还得带上一个括号{}