部署 CloudFlare Argo Tunnel

为什么用CloudFlare Argo Tunnel?

  • 无公网IP的情况下发布Web服务
  • 加速访问速度

旧的部署方式

Web application <- Nginx proxy <- Router NAT <- Iptables proxy <- CloudFlare CDN -> Browser
Web应用IP:8001 <- Nginx应用IP:80 <- 家用宽带IP:8000 <- VPS IP:80 <- CF IP -> 用户IP

新的部署方式

Web application <- Nginx proxy <- cloudflared <- CloudFlare CDN -> Browser

Web应用IP:8001 <- Nginx应用IP:80 <- CF IP <- CF IP -> 用户IP

部署步骤

1. 💰开通Argo💰

每个月5刀,免费1G流量,超出1G 0.1刀
💰💰💰

2. 下载cloudflared

# Debian
wget -q https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb && dpkg -i cloudflared-linux-amd64.deb
# Redhat
wget -q https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-x86_64.rpm && rpm -i cloudflared-linux-x86_64.rpm

3. 配置cloudflare

  • 登陆获取密钥 + 创建隧道
cloudflared tunnel login
cloudflared tunnel create <NAME>
  • 创建配置文件
vim ~/.cloudflare/config.yaml
url: https://localhost:8000
tunnel: <Tunnel-UUID>
credentials-file: /root/.cloudflared/<Tunnel-UUID>.json
no-tls-verify: True #忽略证书错误
  • 添加DNS CNAME记录
cloudflared tunnel route dns <UUID or NAME> <hostname>
  • 运行隧道
cloudflared tunnel run <UUID or NAME>