From b7e093dd682523fd45b7e5c0352ea332dc59c70d Mon Sep 17 00:00:00 2001 From: yczpf2019 Date: Sat, 24 Jan 2026 16:26:52 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E5=AE=8C=E5=96=84=20Nginx=20=E5=8F=8D?= =?UTF-8?q?=E4=BB=A3=E9=85=8D=E7=BD=AE=E5=8F=8A=20WebSocket=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README_VPS.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/README_VPS.md b/README_VPS.md index 3b186d91..e3d19def 100644 --- a/README_VPS.md +++ b/README_VPS.md @@ -43,8 +43,9 @@ npm run build:prod npm start ``` -## 3. 生产环境建议 (进程守护) +## 4. 生产环境建议 (进程守护与反代) +### 4.1 使用 pm2 管理进程 为了保证服务器断开连接后 Mixly 依然运行,建议使用 `pm2`: ```bash @@ -54,13 +55,58 @@ pm2 save pm2 startup ``` -## 4. 跨平台特性说明 +### 4.2 使用 Nginx 反代 (推荐) +如果你想通过域名访问并使用标准端口 (80/443),请参考以下 Nginx 配置: + +```nginx +server { + listen 80; + server_name 你的域名; + return 301 https://$host$request_uri; +} + +server { + listen 443 ssl; + server_name 你的域名; + + ssl_certificate /path/to/your/cert.pem; + ssl_certificate_key /path/to/your/key.pem; + + # 核心配置:处理 WebSocket 和大文件上传 + location / { + proxy_pass https://127.0.0.1:7100; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + + # 允许上传大文件 (如库同步或大项目) + client_max_body_size 100M; + + proxy_connect_timeout 3600s; + proxy_read_timeout 3600s; + proxy_send_timeout 3600s; + } + + # 处理 Socket.io 特殊路径 + location /mixly-socket/ { + proxy_pass https://127.0.0.1:7100; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + } +} +``` + +## 5. 跨平台特性说明 - **路径自动适配**:本项目已重构 `config.js`,部署时会自动识别 Linux 路径,无需手动修改 `config.json`。 - **库文件全内置**:`arduino-libs` 已包含在 Git 仓库中,`git clone` 后即可直接编译带库的工程。 -## 5. 常见问题排查 +## 6. 常见问题排查 - **HTTPS 访问**:默认运行在 `https://你的IP:7100`。 +- **反向代理配置**:如果使用 Nginx 反代,请务必处理好的 WebSocket (Upgrade) 头,否则页面无法连接。 - **上传报错**:如果提示权限不足,请确认当前用户是否在 `dialout` 组,或尝试 `root` 运行(不推荐)。 - **Python 命令**:系统必须能识别 `python3` 命令。