Caddy安装 - CentOS、MacOS

9 篇文章 0 订阅
官网:https://caddyserver.com
GitHub:https://github.com/caddyserver/caddy/releases

linux - CentOS - 7.9

下载二进制文件

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

复制至/usr/local/bin

mv ./caddy /usr/local/bin/

查看caddy版本,测试是否安装成功

caddy version

创建用户组

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
内容如下,可直接复制

# 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

调整权限

chmod 755 caddy.service

在/etc目录下创建文件夹

mkdir caddy

在/etc/caddy/ 添加Caddyfile
默认配置:https://github.com/caddyserver/dist/blob/master/config/Caddyfile
内容如下,可直接复制

# 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

添加系统命令,设置开机启动

ln -s /usr/local/bin/caddy /usr/bin/caddy
systemctl daemon-reload
systemctl enable caddy

启动caddy

systemctl start caddy

查看caddy启动状态

systemctl status caddy

测试一下,查看配置信息

curl localhost:2019/config/

MacOS

安装

brew install caddy

进入安装目录 /usr/local/Cellar/caddy/2.2.1
安装的是2.2.1,可通过caddy version查看。

cd /usr/local/Cellar/caddy/2.2.1
cat homebrew.mxcl.caddy.plist

内容如下

<?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>

这个是Caddyfile配置文件路径

<string>/usr/local/etc/Caddyfile</string>

进入 /usr/local/etc

cd /usr/local/etc

这个时候会发现没有这个文件,安装时没有生成该文件
下面在/usr/local/etc/目录创建caddy文件夹

mkdir caddy
cd caddy

caddy文件夹添加Caddyfile
默认配置文件:https://github.com/caddyserver/dist/blob/master/config/Caddyfile

vi Caddyfile

Caddyfile内容如下,可直接复制

# 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

接下来修改 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>

启动caddy

brew services start caddy

访问:127.0.0.1:2019/config

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值