345 lines
7.1 KiB
Markdown
345 lines
7.1 KiB
Markdown
# XWorld 外网服务器部署检查清单
|
||
|
||
域名:
|
||
|
||
```text
|
||
game.xworld.ren -> Gateway/API/WSS
|
||
www.xworld.ren -> CDN 静态资源
|
||
```
|
||
|
||
公网只开放 `80`、`443` 给 Caddy。`5005`、`15081` 只监听 `127.0.0.1`,不要对公网开放。
|
||
|
||
## 1. DNS 与安全组
|
||
|
||
在域名 DNS 控制台添加 A 记录:
|
||
|
||
```text
|
||
game.xworld.ren A <新服务器公网 IP>
|
||
www.xworld.ren A <新服务器公网 IP>
|
||
```
|
||
|
||
云服务器安全组放行:
|
||
|
||
```text
|
||
TCP 80 入站
|
||
TCP 443 入站
|
||
```
|
||
|
||
不要放行:
|
||
|
||
```text
|
||
TCP 5005
|
||
TCP 15081
|
||
```
|
||
|
||
Windows 防火墙放行:
|
||
|
||
```powershell
|
||
New-NetFirewallRule -DisplayName "Caddy HTTP" -Direction Inbound -Protocol TCP -LocalPort 80 -Action Allow
|
||
New-NetFirewallRule -DisplayName "Caddy HTTPS" -Direction Inbound -Protocol TCP -LocalPort 443 -Action Allow
|
||
```
|
||
|
||
检查 DNS:
|
||
|
||
```powershell
|
||
nslookup game.xworld.ren
|
||
nslookup www.xworld.ren
|
||
```
|
||
|
||
## 2. 准备服务器目录
|
||
|
||
管理员 PowerShell:
|
||
|
||
```powershell
|
||
New-Item -ItemType Directory -Force -Path C:\xworld\app
|
||
New-Item -ItemType Directory -Force -Path C:\xworld\games
|
||
New-Item -ItemType Directory -Force -Path C:\xworld\cdn
|
||
New-Item -ItemType Directory -Force -Path C:\xworld\logs
|
||
New-Item -ItemType Directory -Force -Path C:\caddy
|
||
New-Item -ItemType Directory -Force -Path C:\nssm
|
||
```
|
||
|
||
目录约定:
|
||
|
||
```text
|
||
C:\xworld\app\gateway\ Gateway self-contained 发布产物
|
||
C:\xworld\app\cdn\ CDN Runner self-contained 发布产物
|
||
C:\xworld\games\ 服务端小游戏模块,games\<id>\<ver>\*.dll
|
||
C:\xworld\cdn\ CDN 内容,XWorld\<platform>\... 和 minigame\<id>\<ver>\<platform>\...
|
||
C:\xworld\logs\ NSSM stdout/stderr 日志
|
||
C:\xworld\accounts.db 账号数据库,首次启动自动创建
|
||
C:\xworld\auth.key token 密钥,首次启动自动创建,务必备份
|
||
```
|
||
|
||
## 3. 安装工具
|
||
|
||
下载 Caddy Windows amd64:
|
||
|
||
```text
|
||
https://caddyserver.com/download
|
||
```
|
||
|
||
放到:
|
||
|
||
```text
|
||
C:\caddy\caddy.exe
|
||
```
|
||
|
||
下载 NSSM:
|
||
|
||
```text
|
||
https://nssm.cc/download
|
||
```
|
||
|
||
放到:
|
||
|
||
```text
|
||
C:\nssm\nssm.exe
|
||
```
|
||
|
||
检查:
|
||
|
||
```powershell
|
||
C:\caddy\caddy.exe version
|
||
C:\nssm\nssm.exe version
|
||
```
|
||
|
||
## 4. 发布并上传服务程序
|
||
|
||
在有 .NET 10 SDK 的开发机或构建机上执行:
|
||
|
||
```powershell
|
||
cd C:\XWorld\AIC#Project
|
||
powershell -ExecutionPolicy Bypass -File .\deploy\windows\publish.ps1
|
||
```
|
||
|
||
产物:
|
||
|
||
```text
|
||
deploy\windows\out\xworld-server.zip
|
||
```
|
||
|
||
把 `xworld-server.zip` 上传到新服务器,并解压到 `C:\xworld\app`:
|
||
|
||
```powershell
|
||
Expand-Archive C:\xworld\xworld-server.zip -DestinationPath C:\xworld\app -Force
|
||
```
|
||
|
||
解压后应存在:
|
||
|
||
```text
|
||
C:\xworld\app\gateway\XWorld.Server.Gateway.Runner.exe
|
||
C:\xworld\app\cdn\XWorld.Server.Cdn.Runner.exe
|
||
```
|
||
|
||
不要运行 `Server\...\bin\Release\net10.0\*.exe`,那是 framework-dependent 构建,会要求服务器安装 .NET Runtime。
|
||
|
||
## 5. 上传业务数据
|
||
|
||
上传服务端小游戏模块到:
|
||
|
||
```text
|
||
C:\xworld\games\<id>\<ver>\*.dll
|
||
C:\xworld\games\<id>\<ver>\game.json
|
||
```
|
||
|
||
上传 CDN 内容到:
|
||
|
||
```text
|
||
C:\xworld\cdn\XWorld\android\updatever.txt
|
||
C:\xworld\cdn\XWorld\pc\updatever.txt
|
||
C:\xworld\cdn\minigame\<id>\<ver>\<platform>\...
|
||
```
|
||
|
||
至少先确认一个资源文件存在:
|
||
|
||
```powershell
|
||
Test-Path C:\xworld\cdn\XWorld\android\updatever.txt
|
||
```
|
||
|
||
## 6. 配置 Caddyfile
|
||
|
||
复制仓库里的配置:
|
||
|
||
```powershell
|
||
Copy-Item C:\XWorld\AIC#Project\deploy\windows\Caddyfile C:\xworld\Caddyfile -Force
|
||
```
|
||
|
||
确认核心内容是 `xworld.ren`:
|
||
|
||
```caddyfile
|
||
game.xworld.ren {
|
||
encode zstd gzip
|
||
reverse_proxy 127.0.0.1:5005
|
||
}
|
||
|
||
www.xworld.ren {
|
||
encode zstd gzip
|
||
handle_path /game/60S/* {
|
||
reverse_proxy 127.0.0.1:15081
|
||
}
|
||
respond 404
|
||
}
|
||
```
|
||
|
||
## 7. 先前台启动内层服务
|
||
|
||
开一个 PowerShell 跑 Gateway:
|
||
|
||
```powershell
|
||
C:\xworld\app\gateway\XWorld.Server.Gateway.Runner.exe `
|
||
--gamesRoot C:\xworld\games `
|
||
--port 5005 `
|
||
--authDbPath C:\xworld\accounts.db
|
||
```
|
||
|
||
再开一个 PowerShell 跑 CDN:
|
||
|
||
```powershell
|
||
C:\xworld\app\cdn\XWorld.Server.Cdn.Runner.exe `
|
||
--root C:\xworld\cdn `
|
||
--port 15081
|
||
```
|
||
|
||
检查端口:
|
||
|
||
```powershell
|
||
Get-NetTCPConnection -LocalPort 5005 -State Listen
|
||
Get-NetTCPConnection -LocalPort 15081 -State Listen
|
||
```
|
||
|
||
检查本机 CDN:
|
||
|
||
```powershell
|
||
Invoke-WebRequest http://127.0.0.1:15081/XWorld/android/updatever.txt -UseBasicParsing
|
||
```
|
||
|
||
## 8. 前台启动 Caddy 验证证书
|
||
|
||
另开管理员 PowerShell:
|
||
|
||
```powershell
|
||
C:\caddy\caddy.exe run --config C:\xworld\Caddyfile
|
||
```
|
||
|
||
正常日志应出现:
|
||
|
||
```text
|
||
serving initial configuration
|
||
enabling automatic TLS certificate management
|
||
certificate obtained successfully
|
||
```
|
||
|
||
如果 443 被占用:
|
||
|
||
```powershell
|
||
Get-NetTCPConnection -LocalPort 443 -State Listen | Select-Object LocalAddress,LocalPort,OwningProcess
|
||
```
|
||
|
||
如果返回 `OwningProcess = 4`,通常是 HTTP.sys/IIS 类服务占用,先排查 IIS/WAS/WMSVC。
|
||
|
||
## 9. 外网验证
|
||
|
||
旧版 Windows PowerShell 先启用 TLS 1.2:
|
||
|
||
```powershell
|
||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||
```
|
||
|
||
验证 CDN:
|
||
|
||
```powershell
|
||
Invoke-WebRequest https://www.xworld.ren/game/60S/XWorld/android/updatever.txt -UseBasicParsing
|
||
```
|
||
|
||
应返回 `200`。
|
||
|
||
验证 Gateway:
|
||
|
||
```powershell
|
||
Invoke-WebRequest https://game.xworld.ren -UseBasicParsing
|
||
```
|
||
|
||
`game.xworld.ren` 根路径可能返回 `404`,这是正常的。不要返回 `502`。`502` 说明 Caddy 连不上 `127.0.0.1:5005`。
|
||
|
||
验证端口:
|
||
|
||
```powershell
|
||
Test-NetConnection game.xworld.ren -Port 443
|
||
Test-NetConnection www.xworld.ren -Port 443
|
||
```
|
||
|
||
## 10. 注册 Windows 服务
|
||
|
||
内层服务:
|
||
|
||
```powershell
|
||
powershell -ExecutionPolicy Bypass -File C:\XWorld\AIC#Project\deploy\windows\install-services.ps1 `
|
||
-NssmPath C:\nssm\nssm.exe `
|
||
-OutRoot C:\xworld\app `
|
||
-GamesRoot C:\xworld\games `
|
||
-CdnRoot C:\xworld\cdn `
|
||
-AuthDbPath C:\xworld\accounts.db `
|
||
-LogDir C:\xworld\logs
|
||
```
|
||
|
||
Caddy 服务:
|
||
|
||
```powershell
|
||
C:\nssm\nssm.exe install XWorldCaddy C:\caddy\caddy.exe
|
||
C:\nssm\nssm.exe set XWorldCaddy AppParameters "run --config C:\xworld\Caddyfile"
|
||
C:\nssm\nssm.exe set XWorldCaddy AppDirectory C:\xworld
|
||
C:\nssm\nssm.exe set XWorldCaddy Start SERVICE_AUTO_START
|
||
C:\nssm\nssm.exe set XWorldCaddy AppStdout C:\xworld\logs\caddy.out.log
|
||
C:\nssm\nssm.exe set XWorldCaddy AppStderr C:\xworld\logs\caddy.err.log
|
||
C:\nssm\nssm.exe start XWorldCaddy
|
||
```
|
||
|
||
查看服务:
|
||
|
||
```powershell
|
||
Get-Service XWorldGateway,XWorldCdn,XWorldCaddy
|
||
```
|
||
|
||
## 11. 最终检查
|
||
|
||
```powershell
|
||
Get-NetTCPConnection -LocalPort 80 -State Listen
|
||
Get-NetTCPConnection -LocalPort 443 -State Listen
|
||
Get-NetTCPConnection -LocalPort 5005 -State Listen
|
||
Get-NetTCPConnection -LocalPort 15081 -State Listen
|
||
```
|
||
|
||
预期:
|
||
|
||
```text
|
||
80/443 Caddy 监听
|
||
5005 Gateway 监听 127.0.0.1
|
||
15081 CDN 监听 127.0.0.1
|
||
```
|
||
|
||
确认客户端生产常量:
|
||
|
||
```text
|
||
ProductionResBase = https://www.xworld.ren/game/60S/
|
||
ProductionGatewayUrl = wss://game.xworld.ren/ws
|
||
ProductionAuthBase = https://game.xworld.ren
|
||
```
|
||
|
||
改完域名后需要重新出客户端包。
|
||
|
||
## 12. 关键备份
|
||
|
||
必须备份:
|
||
|
||
```text
|
||
C:\xworld\accounts.db
|
||
C:\xworld\auth.key
|
||
C:\xworld\games\
|
||
C:\xworld\cdn\
|
||
C:\xworld\Caddyfile
|
||
```
|
||
|
||
`auth.key` 丢失后,所有已签发 token 都会失效,用户需要重新登录。
|
||
|