1,常用shell
#!/bin/sh
# 文件名: quit.sh
# 退出caddy
./caddy stop
exit 0
----------------------------------
#!/bin/sh
# 文件名:reload.sh
# 重新加载caddy配置文件
./caddy reload --config ./Caddyfile
----------------------------------
#!/bin/sh
# 文件名:start.sh
# 启动caddy
# ./caddy start --config /home/datum/program/caddyapp/Caddyfile
# cd /home/datum/program/caddyapp
./caddy start --config ./Caddyfile
exit 0
----------------------------------
#!/bin/sh
# 文件名:validate.sh
# 验证caddy配置文件
# ./caddy validate --config /home/datum/program/caddyapp/Caddyfile
# cd /home/datum/program/caddyapp
./caddy validate --config ./Caddyfile
2,文件夹目录示例
# 公开文件,用于下载,传输
https://ac1.taobao8.cc:443 {
handle_path /openfile/* {
root * /home/check/openfile
file_server {
hide *.git
browse
}
}
}
3,代理静态网页
http://test2.taobao8.com:80 https://test2.taobao8.com:443 {
handle_path /* {
file_server {
hide .git
index index.html
}
root * /home/webapp/myhtml/page/h5
try_files {path} /index.html
}
}
4,代理http端口
# http后端接口
http://check1.taobao8.ai:80, https://check1.taobao8.ai:443 {
import cors
# 代理本地 15003 端口的http服务
route /* {
#uri strip_prefix /taobao8-api
reverse_proxy * {
to http://localhost:15003
lb_policy client_ip_hash
header_down -'proxy-connection'
flush_interval 300ms
transport http {
dial_timeout 10s
keepalive 10m
}
}
}
# 代理本地 15008 端口的http服务,url中的域名后面的路径要加/taobao8-api/
route /taobao8-api/* {
uri strip_prefix /taobao8-api
reverse_proxy * {
to http://localhost:15008
lb_policy client_ip_hash
header_down -'proxy-connection'
flush_interval 300ms
transport http {
dial_timeout 10s
keepalive 10m
}
}
}
# 将xxl-job的整理服务放出来
handle_path /xxljob/* {
uri strip_prefix /xxljob
reverse_proxy * {
to http://localhost:15038
lb_policy client_ip_hash
header_down -'proxy-connection'
flush_interval 300ms
transport http {
dial_timeout 10s
keepalive 10m
}
}
}
}
5,caddy另外指定域名的证书
先在caddy根目录下创建文件夹ssl_dir,把证书都放进去,假设静态网页在机器 10.0.0.5 上,对外 端口是8081,域名为 www.mydomain.com,证书为 mydomain.pem ,私钥为: mydomain.key
https://www.mydomain.com {
tls ./ssl_dir/mydomain.pem ./ssl_dir/mydomain.key
import block__handle_strip_path_and_proxy_args * * http://10.0.0.5:8081
}