📢 本文由 gemini-3.5-flash 翻譯
全 Docker 部署使用 frp 進行內網穿透,嘗試了一下速度還不錯,延遲可以接受
設定 DNS
需要自己有一台公網伺服器,這裡我的 SSL 憑證是透過 Cloudflare 進行設定的,所以我的全部連線是透過 80 連接埠
設定幾個網域,分別是連線 frp 的網域 (例如 frp.example.com ),然後是自己需要代理的服務 (例如 server1.example.com, server2.example.com) 指向伺服器,注意連線 frp 的網域 (frp.example.com) 不能啟用 Cloudflare 代理,也就是使用僅 DNS 模式
伺服器端
在伺服器上安裝 frp 較為簡單,準備設定檔 frps.toml
1
2
3
4
5
| bindPort = 7000
vhostHTTPPort = 8000
auth.method = "token"
auth.token = "set_your_token"
|
設定一個複雜的 token 然後是 docker-compose.yml
1
2
3
4
5
6
7
8
9
10
| services:
frps:
image: snowdreamtech/frps:latest
container_name: frps
restart: unless-stopped
ports:
- "7000:7000"
- "8000:8000"
volumes:
- ./frps.toml:/etc/frp/frps.toml
|
直接啟動即可
設定 Nginx
將連線 frp 的網域 (frp.example.com) 反向代理至 bindPort = 7000 也就是 172.17.0.1:7000
然後將所有的服務網域都反向代理至 vhostHTTPPort = 8000 也就是 172.17.0.1:8000
因為使用 Cloudflare 代理,所以不能只使用一個 Nginx 設定 server_name 為這些網域,不然只有第一個網域會生效,所以每個網域需要單獨設定,但每個都反向代理至 172.17.0.1:8000
客戶端
客戶端的設定較為複雜,設定檔 frpc.toml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| serverAddr = "frp.example.com"
serverPort = 80
transport.protocol = "websocket"
auth.method = "token"
auth.token = "set_your_token"
[[proxies]]
name = "nas-server1"
type = "http"
localIP = "192.168.6.x"
localPort = 8001
customDomains = ["server1.example.com"]
[[proxies]]
name = "nas-server2"
type = "http"
localIP = "192.168.6.x"
localPort = 8002
customDomains = ["server2.example.com"]
|
然後是 docker-compose.yml
1
2
3
4
5
6
7
8
| services:
frpc:
image: snowdreamtech/frpc:latest
container_name: frpc
restart: unless-stopped
network_mode: "host"
volumes:
- "./frpc.toml:/etc/frp/frpc.toml"
|
直接啟動即可