Caddy是一个由Go语言编写的Web服务器软件,可以自动实现HTTPS部署。
使用caddy作为web服务器
为什么使用Caddy
自己的博客想要使用https,懒得去更新证书,Caddy可以快速解决我的问题。
安装Caddy
在CentOS上可以直接使用yum安装的,也可以下载对应平台的二进制进行安装。
使用caddy作为web服务器
安装命令:
yum install yum-plugin-copr -y
yum copr enable @caddy/caddy -y
yum install caddy -y
配置
配置文件默认是在/etc/caddy/Caddyfile,配置文件只要修改好自己的域名,如果需要https直接填写上http://xxx就可以了,root执行自己的网站目录即可。
我的网站是hugo生成的静态站,直接配置目录。
如果是php可以直接转发的php_fastcgi。
# 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.
www.opcai.top https://www.opcai.top http://opcai.top https://opcai.top {
# Set this path to your site's directory.
root * /data/webroot
# Enable the static file server.
file_server
# Another common task is to set up a reverse proxy:
# reverse_proxy /back/* 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
服务管理
systemctl enable --now caddy # 启动并设置开机启动
systemctl reload caddy # 重载配置
大型站长资讯类网站! https://www.0818zz.com