seo优化方法网站快速排名推广渠道,大连网站制作报价,wordpress企业模版,城乡和住房建设厅网站首页利用Caddy实现http反向代理
1 Caddy是什么
Caddy是一个开源的#xff0c;使用Golang编写的#xff0c;支持HTTP/2的Web服务端。它的一个显著特征就是默认启用HTTPS。
和nginx类似。
2 多个后端服务
假如现在有3个后端http服务#xff1a;分别在启动在
app1
http://10…利用Caddy实现http反向代理
1 Caddy是什么
Caddy是一个开源的使用Golang编写的支持HTTP/2的Web服务端。它的一个显著特征就是默认启用HTTPS。
和nginx类似。
2 多个后端服务
假如现在有3个后端http服务分别在启动在
app1
http://10.0.0.1:8080GET /
GET /pingapp2
http://10.0.0.2:8080GET /
GET /pingapp3
http://10.0.0.3:8080GET /
GET /ping3 Caddyfile
localhost {# localhost/app1/ping - http://10.0.0.1:8080/pingroute /app1/* {uri strip_prefix /app1reverse_proxy http://10.0.0.1:8080}route /app2/* {uri strip_prefix /app2reverse_proxy http://10.0.0.2:8080}route /app3/* {uri strip_prefix /app3reverse_proxy http://10.0.0.3:8080}
}Tips uri strip_prefix /app1的作用是将url中的/app1给去掉然后转发到reverse_proxy上去。 启动caddy
$ caddy run此时使用curl或者浏览器访问
$ curl -v http://localhost/app1/ping
$ curl -v http://localhost/app2/ping
$ curl -v http://localhost/app3/ping则caddy会分别反向代理到app1、app2、app3上。
4 启用HTTPS
自签证书
本地测试的时候需要安装本地信任机构CA并且自签证书需要借助mkcert工具
$ brew install mkcert安装CA到本机
$ mkcert -install为主机自签证书
$ mkcert example.org会在当前目录生成example.org.pem和example.org-key.pem这两个文件
配置Hosts
在hosts文件里添加
127.0.0.1 example.org此时访问example.org就会访问到本机的127.0.0.1
在Caddyfile中添加tls
example.org {tls /Users/example.org.pem /Users/example.org-key.pem# example.org/app1/ping - http://10.0.0.1:8080/pingroute /app1/* {uri strip_prefix /app1reverse_proxy http://10.0.0.1:8080}route /app2/* {uri strip_prefix /app2reverse_proxy http://10.0.0.2:8080}route /app3/* {uri strip_prefix /app3reverse_proxy http://10.0.0.3:8080}
}需要注意的是tls配置的 xx.pem和xx-key.pem文件是绝对路径。
重启caddy