Caddy
类似于Apache,Nginx,是一个高性能的HTTP和反向代理服务器
代码
https://github.com/mholt/caddy
使用,先升级Go至1.9以上(https://my.oschina.net/u/2601...,然后
go get github.com/mholt/caddy/caddy
go get github.com/caddyserver/builds
cd $GOPATH/src/github.com/mholt/caddy/caddy
go run build.go
./caddy
初步尝试,在caddy同目录下创建Caddyfile文件,并写入配置,然后运行caddy
# cat Caddyfile
0.0.0.0:2015
push
browse
websocket /echo cat
ext .html
log /var/log/access.log
proxy /api 127.0.0.1:7005
header /api Access-Control-Allow-Origin *
#
# ./caddy
Activating privacy features... done.
http://0.0.0.0:2015
效果如图,运行了一个简单的文件服务器
开启https,需要加一行配置tls /root/ca.pem /root/ca-key.pem,如图:
# cat Caddyfile
0.0.0.0:2015 {
gzip
tls /etc/ssl/caddy/ca.pem /etc/ssl/caddy/ca-key.pem
#tls xxxx@qq.com {
# protocols tls1.0 tls1.2
#}
push
browse
websocket /echo cat
ext .html
log /var/log/access.log
proxy /api 127.0.0.1:7005
header /api Access-Control-Allow-Origin *
}
# ./caddy
Activating privacy features... done.
https://0.0.0.0:2015
看到有很多帖子说Caddy可以自动申请证书,但我尝试了多次都没有成功。墙外的虚机也不行……
反向代理,简单配置如下,给原来的web服务直接加了https,挺好。
0.0.0.0:2015 {
gzip
tls /root/ca.pem /root/ca-key.pem
proxy / http://localhost:8080 {
header_upstream Host {host}
header_upstream X-Real-IP {remote}
header_upstream X-Forwarded-For {remote}
header_upstream X-Forwarded-Proto {scheme}
}
}
有疑问加站长微信联系(非本文作者)