Caddy安装 - CentOS、MacOS

官网: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
1
解压

tar -zxf caddy_2.2.1_linux_amd64.tar.gz caddy
1
复制至/usr/local/bin

mv ./caddy /usr/local/bin/
1
查看caddy版本,测试是否安装成功

caddy version
1
创建用户组

groupadd --system caddy
1
添加用户

useradd --system \
--gid caddy \
--create-home \
--home-dir /var/lib/caddy \
--shell /usr/sbin/nologin \
--comment "Caddy web server" \
caddy
1
2
3
4
5
6
7
添加 /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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
调整权限

chmod 755 caddy.service
1
在/etc目录下创建文件夹

mkdir caddy
1
在/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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
添加系统命令,设置开机启动

ln -s /usr/local/bin/caddy /usr/bin/caddy
systemctl daemon-reload
systemctl enable caddy
1
2
3
启动caddy

systemctl start caddy
1
查看caddy启动状态

systemctl status caddy
1
测试一下,查看配置信息

curl localhost:2019/config/
1
MacOS
安装

brew install caddy
1
进入安装目录 /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
1
2
内容如下

<?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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
这个是Caddyfile配置文件路径

<string>/usr/local/etc/Caddyfile</string>
1
进入 /usr/local/etc

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

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

vi Caddyfile
1
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
接下来修改 homebrew.mxcl.caddy.plist 文件

cd /usr/local/Cellar/caddy/2.2.1
vi homebrew.mxcl.caddy.plist
1
2
<string>/usr/local/etc/Caddyfile</string>
修改为
<string>/usr/local/etc/caddy/Caddyfile</string>
1
2
3
启动caddy

brew services start caddy
1
访问:127.0.0.1:2019/config
————————————————
版权声明:本文为CSDN博主「懒人程序猿」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_18361349/article/details/111027490

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值