Skip to content

Instantly share code, notes, and snippets.

@wyf9
Last active October 19, 2025 09:39
Show Gist options
  • Select an option

  • Save wyf9/71ff358636154ab00d90602c3c818763 to your computer and use it in GitHub Desktop.

Select an option

Save wyf9/71ff358636154ab00d90602c3c818763 to your computer and use it in GitHub Desktop.
在 Huggingface Space 中后台启动 Cloudflared
# Cloudflare script for Huggingface by wyf9
echo "[CFD] v2025.7.18.1"
# * 使用说明:
# 在 Dockerfile 中添加: RUN wget -O cfd.sh https://gist.github.com/wyf9/71ff358636154ab00d90602c3c818763/raw/cfd.sh
# 并将启动命令改为 CMD bash cfd.sh
# 需要提前安装 wget: CMD apt install wget -y
# * 配置环境变量:
# CFD_TOKEN: 你的隧道 token
# CFD_COMMAND: 原本的启动命令
# 下载 cloudflared
echo "[CFD] downloading executable file"
wget -O cexec https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64
# 可执行权限
chmod +x cexec
# 启动原本的程序
echo "[CFD] execute cmd: $CFD_COMMAND"
$CFD_COMMAND &
# 指定端口启动 Simple HTTP (需要 python3)
if [ -n "$CFD_PORT" ]; then
if [ -n "$CFD_LOCATION" ]; then
echo '
from http.server import BaseHTTPRequestHandler, HTTPServer
class SimpleHandler(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(302)
self.send_header("Content-type", "text/plain")
self.send_header("Location", "'$CFD_LOCATION'")
self.end_headers()
self.wfile.write(b"")
server_address = ("", '$CFD_PORT')
httpd = HTTPServer(server_address, SimpleHandler)
print("Server running on port '$CFD_PORT'...")
httpd.serve_forever()
' | python3
fi
# 启动!
echo "[CFD] starting tun"
./cexec tunnel --protocol=http2 --no-autoupdate --edge-ip-version auto run --token $CFD_TOKEN
@ntkrnl32
Copy link

wget not found D:

@wyf9
Copy link
Author

wyf9 commented Apr 16, 2025

wget not found D:

# 需要提前安装 wget: CMD apt install wget -y

install wget 1st

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment