地址。按官网所说安装。
Caddy为golang程序,不会有各种依赖,单独的一个文件就是执行程序,cp到 /usr/local/bin就安装完成了。
输入whereis caddy可以看到 /usr/bin/caddy,/etc/caddy/Caddyfile,/usr/share/caddy,其中etc/caddy/Caddyfile是配置文件。编辑配置文件 vim Caddyfile:
1 2 3 4
| { admin off } import /etc/caddy/sites/*.conf
|
再在 /etc/caddy 下新建 sites 文件夹,此后,将配置文件写里面即可。
配置文件 vim example.com.conf:
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| example.com { root * /var/www file_server }
example.com:80 { root * /var/www file_server }
http://example.com:xxxx { root * /var/www file_server }
example.com { root * /var/www tls 公钥路径 私钥路径 file_server }
example1.com, example2.com { root * /var/www file_server }
example.com { reverse_proxy localhost:8888 reverse_proxy /example localhost:8888 reverse_proxy / localhost:8888/example/ reverse_proxy /ws 127.0.0.1:8888 }
example1.com { redir https://example2.com{url} }
example1.com { redir https://example2.com{url} permanent }
example.com { reverse_proxy localhost:x localhost:y { lb_policy first } }
|
一个比较全面的caddy配置文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| example.com { gzip browse log /etc/caddy/log/access.log revers_proxy localhost:xxxx {
} errors { log /etc/caddy/log/error.log { size 50 age 30 keep 5 } } }
|
修改配置后,systemctl reload caddy重加载配置。