Initial commit: FunConnect project with server, relay, client and admin panel
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
218
docs/NO_PUBLIC_IP.md
Normal file
218
docs/NO_PUBLIC_IP.md
Normal file
@@ -0,0 +1,218 @@
|
||||
# 无公网 IP 部署方案
|
||||
|
||||
如果你的服务器没有公网 IP(比如家庭宽带、公司内网),可以使用以下方案:
|
||||
|
||||
## 方案一:使用云服务器(推荐)
|
||||
|
||||
购买一台云服务器(阿里云、腾讯云、AWS 等),价格低至几十元/月:
|
||||
|
||||
```bash
|
||||
# 在云服务器上一键部署
|
||||
curl -fsSL https://raw.githubusercontent.com/mofangfang/funmc/main/deploy.sh | bash
|
||||
```
|
||||
|
||||
优点:
|
||||
- 稳定可靠,24小时在线
|
||||
- 有固定公网 IP
|
||||
- 部署简单
|
||||
|
||||
## 方案二:使用内网穿透工具
|
||||
|
||||
### 使用 frp(免费开源)
|
||||
|
||||
1. **在有公网 IP 的服务器上部署 frps**
|
||||
|
||||
```bash
|
||||
# 下载 frp
|
||||
wget https://github.com/fatedier/frp/releases/download/v0.52.0/frp_0.52.0_linux_amd64.tar.gz
|
||||
tar -xzf frp_0.52.0_linux_amd64.tar.gz
|
||||
cd frp_0.52.0_linux_amd64
|
||||
|
||||
# 配置 frps.toml
|
||||
cat > frps.toml << 'EOF'
|
||||
bindPort = 7000
|
||||
auth.token = "your_secret_token"
|
||||
EOF
|
||||
|
||||
# 启动
|
||||
./frps -c frps.toml
|
||||
```
|
||||
|
||||
2. **在内网服务器上部署 frpc + FunMC**
|
||||
|
||||
```bash
|
||||
# 先部署 FunMC
|
||||
docker-compose up -d
|
||||
|
||||
# 配置 frpc.toml
|
||||
cat > frpc.toml << 'EOF'
|
||||
serverAddr = "你的frps服务器IP"
|
||||
serverPort = 7000
|
||||
auth.token = "your_secret_token"
|
||||
|
||||
[[proxies]]
|
||||
name = "funmc-api"
|
||||
type = "tcp"
|
||||
localIP = "127.0.0.1"
|
||||
localPort = 3000
|
||||
remotePort = 3000
|
||||
|
||||
[[proxies]]
|
||||
name = "funmc-quic"
|
||||
type = "udp"
|
||||
localIP = "127.0.0.1"
|
||||
localPort = 3001
|
||||
remotePort = 3001
|
||||
|
||||
[[proxies]]
|
||||
name = "funmc-relay1"
|
||||
type = "udp"
|
||||
localIP = "127.0.0.1"
|
||||
localPort = 7900
|
||||
remotePort = 7900
|
||||
|
||||
[[proxies]]
|
||||
name = "funmc-relay2"
|
||||
type = "udp"
|
||||
localIP = "127.0.0.1"
|
||||
localPort = 7901
|
||||
remotePort = 7901
|
||||
EOF
|
||||
|
||||
# 启动 frpc
|
||||
./frpc -c frpc.toml
|
||||
```
|
||||
|
||||
### 使用 Cloudflare Tunnel(免费)
|
||||
|
||||
适合只需要 HTTP/WebSocket 的场景(不支持 UDP,中继功能需要单独处理):
|
||||
|
||||
```bash
|
||||
# 安装 cloudflared
|
||||
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o cloudflared
|
||||
chmod +x cloudflared
|
||||
|
||||
# 登录
|
||||
./cloudflared tunnel login
|
||||
|
||||
# 创建隧道
|
||||
./cloudflared tunnel create funmc
|
||||
|
||||
# 配置
|
||||
cat > ~/.cloudflared/config.yml << 'EOF'
|
||||
tunnel: funmc
|
||||
credentials-file: ~/.cloudflared/<tunnel-id>.json
|
||||
|
||||
ingress:
|
||||
- hostname: funmc.your-domain.com
|
||||
service: http://localhost:3000
|
||||
- service: http_status:404
|
||||
EOF
|
||||
|
||||
# 添加 DNS 记录
|
||||
./cloudflared tunnel route dns funmc funmc.your-domain.com
|
||||
|
||||
# 启动
|
||||
./cloudflared tunnel run funmc
|
||||
```
|
||||
|
||||
**注意**: Cloudflare Tunnel 不支持 UDP,中继服务器需要单独使用 frp 或其他方案。
|
||||
|
||||
### 使用 Ngrok(简单但有限制)
|
||||
|
||||
```bash
|
||||
# 安装
|
||||
curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc
|
||||
echo "deb https://ngrok-agent.s3.amazonaws.com buster main" | sudo tee /etc/apt/sources.list.d/ngrok.list
|
||||
sudo apt update && sudo apt install ngrok
|
||||
|
||||
# 配置 token
|
||||
ngrok config add-authtoken <your-token>
|
||||
|
||||
# 启动(免费版每次地址会变)
|
||||
ngrok http 3000
|
||||
```
|
||||
|
||||
## 方案三:使用 ZeroTier/Tailscale 组建虚拟局域网
|
||||
|
||||
适合小团队内部使用:
|
||||
|
||||
### Tailscale
|
||||
|
||||
```bash
|
||||
# 服务器和所有客户端都安装 Tailscale
|
||||
curl -fsSL https://tailscale.com/install.sh | sh
|
||||
tailscale up
|
||||
|
||||
# 使用 Tailscale 分配的内网 IP 访问
|
||||
# 例如:100.x.x.x:3000
|
||||
```
|
||||
|
||||
### ZeroTier
|
||||
|
||||
```bash
|
||||
# 安装
|
||||
curl -s https://install.zerotier.com | sudo bash
|
||||
|
||||
# 加入网络
|
||||
sudo zerotier-cli join <network-id>
|
||||
|
||||
# 使用 ZeroTier 分配的内网 IP
|
||||
```
|
||||
|
||||
## 方案四:端口映射(如果路由器支持)
|
||||
|
||||
如果你的宽带有公网 IP(可能是动态的):
|
||||
|
||||
1. 登录路由器管理页面
|
||||
2. 找到 "端口映射" 或 "虚拟服务器" 或 "NAT"
|
||||
3. 添加映射规则:
|
||||
- 外部端口 3000 -> 内部 IP:3000 (TCP)
|
||||
- 外部端口 3001 -> 内部 IP:3001 (UDP)
|
||||
- 外部端口 7900 -> 内部 IP:7900 (UDP)
|
||||
- 外部端口 7901 -> 内部 IP:7901 (UDP)
|
||||
|
||||
4. 使用动态 DNS(DDNS)获取固定域名:
|
||||
- 花生壳
|
||||
- No-IP
|
||||
- DuckDNS
|
||||
|
||||
## 配置客户端连接
|
||||
|
||||
无论使用哪种方案,都需要更新 FunMC 服务器配置:
|
||||
|
||||
```bash
|
||||
# 编辑 .env 文件
|
||||
nano /opt/funmc/.env
|
||||
|
||||
# 设置为穿透后的公网地址
|
||||
SERVER_IP=frps服务器IP
|
||||
# 或者设置域名
|
||||
SERVER_DOMAIN=funmc.your-domain.com
|
||||
```
|
||||
|
||||
然后重启服务:
|
||||
|
||||
```bash
|
||||
docker-compose restart
|
||||
```
|
||||
|
||||
## 客户端连接流程
|
||||
|
||||
1. 客户端启动时会显示服务器连接页面
|
||||
2. 输入穿透后的地址(如 `frps服务器IP:3000` 或 `funmc.your-domain.com`)
|
||||
3. 客户端会自动获取服务器配置
|
||||
4. 之后每次启动都会自动连接
|
||||
|
||||
## 推荐方案
|
||||
|
||||
| 场景 | 推荐方案 |
|
||||
|------|---------|
|
||||
| 生产环境/公开服务 | 云服务器 |
|
||||
| 个人/小团队 | frp + 便宜云服务器 |
|
||||
| 内部测试 | Tailscale/ZeroTier |
|
||||
| 临时使用 | Ngrok |
|
||||
|
||||
---
|
||||
|
||||
**魔幻方开发** - 让 Minecraft 联机变得简单
|
||||
Reference in New Issue
Block a user