快速上手
最小可用配置
假设:Cloudflare 侧已经建好一条具名隧道,且有一个主机名(如 app.example.com)路由到它; 本机 nginx 有一个 127.0.0.1:8080 的 server。
nginx
# /etc/nginx/nginx.conf
include /etc/nginx/modules-enabled/*.conf;
http {
# 1) 凭据:三选一(这里用控制台给的 token)
cfd_tunnel_token eyJhIjoi...;
# 2) 边缘地址(可选,默认就是 region1.v2.argotunnel.com:7844)
cfd_tunnel_edge region1.v2.argotunnel.com:7844;
# 3) 边缘送来的请求注入到哪个 listen
cfd_tunnel_inject_listen 127.0.0.1:8080;
server {
listen 127.0.0.1:8080;
server_name app.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header CF-Connecting-IP $http_cf_connecting_ip;
}
}
}bash
nginx -t && systemctl restart nginx确认它在跑
bash
grep -E 'cfd_tunnel' /var/log/nginx/error.log | tail -20成功时会看到 NOTICE 级别的两行(形状固定,可以 grep):
text
cfd_tunnel: 已注册到边缘(location=region1.v2.argotunnel.com),注入目标 127.0.0.1:8080然后从 Cloudflare 侧访问 https://app.example.com/,请求应当落到上面那个 location, access_log 里会有对应记录。
常见的第一天问题
| 症状 | 先看哪里 |
|---|---|
error_log 里什么都没有 | include /etc/nginx/modules-enabled/*.conf; 有没有、是不是 reload 而不是 restart |
| 「三种凭据来源都没写」= 模块静默不启用 | 没配 cfd_tunnel_credentials / cfd_tunnel_token / cfd_tunnel_token_file,也没开 quick_tunnel |
| 「读取凭据失败」 | 凭据文件权限:必须是 worker 用户可读(chown www-data:www-data + chmod 600) |
| token 明明贴对了却报错 | 内联 token 不 trim:尾部换行/空格会让 base64 非法,改用 _token_file 或删掉空白 |
| 101 或大文件传不上 | client_max_body_size(默认 1m)与 client_body_timeout(默认 60s) |
| 边缘回 502 / 502 页 | 见 远程配置下发 的「不支持的 service」一节 |