Last active
February 16, 2026 21:00
-
-
Save wyf9/71ff358636154ab00d90602c3c818763 to your computer and use it in GitHub Desktop.
在 Huggingface Space 中后台启动 Cloudflared
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
Author
这是什么意思
@luckylemonade24 你的源有问题,没 wget
把 wget 那行换成
curl -o cexec https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64然后删掉 apt install wget 那行
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
--> RUN apt install wget -y
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Reading package lists...
Building dependency tree...
Reading state information...
Error: Unable to locate package wget
--> ERROR: process "/bin/sh -c apt install wget -y" did not complete successfully: exit code: 100
这是什么意思