Caddy安装和常用命令
记录Caddy的相关内容
实验环境
:Centos7
1. 安装
centos
1 | sudo yum install epel-release #添加源 |
ubuntu16.04+
- 安装和配置
1
2
3
4
5
6
7
8
9curl https://getcaddy.com | bash
sudo mkdir /etc/caddy
sudo chown -R root:www-data /etc/caddy
sudo mkdir /etc/ssl/caddy
sudo chown -R www-data:root /etc/ssl/caddy
sudo chmod 0770 /etc/ssl/caddy
sudo touch /etc/caddy/Caddyfile
sudo mkdir /var/www
sudo chown www-data: /var/www - 添加caddy到service用vim将下面内容写入到文件中
1
vim /lib/systemd/system/caddy.service
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
36[Unit]
Description=Caddy HTTP/2 web server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target
[Service]
Restart=on-failure
StartLimitInterval=86400
StartLimitBurst=5
User=www-data
Group=www-data
; Letsencrypt-issued certificates will be written to this directory.
Environment=CADDYPATH=/etc/ssl/caddy
ExecStart=/usr/local/bin/caddy -log stdout -agree=true -conf=/etc/caddy/Caddyfile -root=/var/tmp
ExecReload=/bin/kill -USR1 $MAINPID
LimitNOFILE=1048576
LimitNPROC=64
PrivateTmp=true
PrivateDevices=true
ProtectHome=true
ProtectSystem=full
ReadWriteDirectories=/etc/ssl/caddy
; The following additional security directives only work with systemd v229 or later.
; They further retrict privileges that can be gained by caddy. Uncomment if you like.
; Note that you may have to add capabilities required by any plugins in use.
;CapabilityBoundingSet=CAP_NET_BIND_SERVICE
;AmbientCapabilities=CAP_NET_BIND_SERVICE
;NoNewPrivileges=true
[Install]
WantedBy=multi-user.target
2. 配置文件默认路径
1 | /etc/caddy/conf.d/Caddyfile.conf |
3.配置文件格式模板
- 注意符号后面含有
空格
- 以下配置主要支持在本地某个端口含有服务,将端口与域名映射起来
1 | https://blog.xxx.xx { |
其中:
- 注意网址替换为自己的网址
- 邮箱是用于SSL证书注册邮箱
- 2888为端口号,需要替换为服务对应的端口号
相关文章