官網(wǎng):https://caddyserver.com
GitHub:https://github.com/caddyserver/caddy/releases
linux - CentOS - 7.9
下載二進(jìn)制文件
wget https://github.com/caddyserver/caddy/releases/download/v2.2.1/caddy_2.2.1_linux_amd64.tar.gz
解壓
tar -zxf caddy_2.2.1_linux_amd64.tar.gz caddy
復(fù)制至/usr/local/bin
mv ./caddy /usr/local/bin/
查看caddy版本够掠,測(cè)試是否安裝成功
caddy version
創(chuàng)建用戶組
groupadd --system caddy
添加用戶
useradd --system \
--gid caddy \
--create-home \
--home-dir /var/lib/caddy \
--shell /usr/sbin/nologin \
--comment "Caddy web server" \
caddy
添加 /etc/systemd/system/caddy.service
文件地址:caddy.service:https://github.com/caddyserver/dist/blob/master/init/caddy.service
內(nèi)容如下觉鼻,可直接復(fù)制
# caddy.service
#
# For using Caddy with a config file.
#
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
#
# See https://caddyserver.com/docs/install for instructions.
#
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.
[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target
[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
調(diào)整權(quán)限
chmod 755 caddy.service
在/etc目錄下創(chuàng)建文件夾
mkdir caddy
在/etc/caddy/ 添加Caddyfile
默認(rèn)配置:https://github.com/caddyserver/dist/blob/master/config/Caddyfile
內(nèi)容如下,可直接復(fù)制
# 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 the line below with your
# domain name.
:80
# Set this path to your site's directory.
root * /usr/share/caddy
# 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
添加系統(tǒng)命令伐割,設(shè)置開機(jī)啟動(dòng)
ln -s /usr/local/bin/caddy /usr/bin/caddy
systemctl daemon-reload
systemctl enable caddy
啟動(dòng)caddy
systemctl start caddy
查看caddy啟動(dòng)狀態(tài)
systemctl status caddy
測(cè)試一下诫咱,查看配置信息
curl localhost:2019/config/
MacOS
安裝
brew install caddy
進(jìn)入安裝目錄 /usr/local/Cellar/caddy/2.2.1
安裝的是2.2.1笙隙,可通過(guò)caddy version查看。
cd /usr/local/Cellar/caddy/2.2.1
cat homebrew.mxcl.caddy.plist
內(nèi)容如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>homebrew.mxcl.caddy</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/caddy/bin/caddy</string>
<string>run</string>
<string>--config</string>
<string>/usr/local/etc/Caddyfile</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>/usr/local/var/log/caddy.log</string>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/caddy.log</string>
</dict>
</plist>
這個(gè)是Caddyfile配置文件路徑
<string>/usr/local/etc/Caddyfile</string>
進(jìn)入 /usr/local/etc
cd /usr/local/etc
這個(gè)時(shí)候會(huì)發(fā)現(xiàn)沒(méi)有這個(gè)文件坎缭,安裝時(shí)沒(méi)有生成該文件
下面在/usr/local/etc/目錄創(chuàng)建caddy文件夾
mkdir caddy
cd caddy
caddy文件夾添加Caddyfile
默認(rèn)配置文件:https://github.com/caddyserver/dist/blob/master/config/Caddyfile
vi Caddyfile
Caddyfile內(nèi)容如下竟痰,可直接復(fù)制
# 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 the line below with your
# domain name.
:80
# Set this path to your site's directory.
root * /usr/share/caddy
# 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
接下來(lái)修改 homebrew.mxcl.caddy.plist 文件
cd /usr/local/Cellar/caddy/2.2.1
vi homebrew.mxcl.caddy.plist
<string>/usr/local/etc/Caddyfile</string>
修改為
<string>/usr/local/etc/caddy/Caddyfile</string>
啟動(dòng)caddy
brew services start caddy
訪問(wèn):127.0.0.1:2019/config