modified nginx mode

This commit is contained in:
2026-08-16 16:29:13 +08:00
parent 2d48c127f9
commit c90df866c1
3 changed files with 22 additions and 8 deletions

View File

@@ -30,7 +30,7 @@
| MOSS | `127.0.0.1:8001` | 内部语音转写 | | MOSS | `127.0.0.1:8001` | 内部语音转写 |
| Whisper | `127.0.0.1:9000` | 内部语音转写Whisper 方案,见第 2A 节) | | Whisper | `127.0.0.1:9000` | 内部语音转写Whisper 方案,见第 2A 节) |
| FastAPI | `127.0.0.1:8000` | 内部应用服务 | | FastAPI | `127.0.0.1:8000` | 内部应用服务 |
| Nginx | `0.0.0.0:443` | 对 HTTPS | | Nginx | `0.0.0.0:80` | 对 HTTP 回源HTTPS 由总出口终结) |
不要把 MOSS/Whisper 的转写端口直接暴露到公网。 不要把 MOSS/Whisper 的转写端口直接暴露到公网。
@@ -238,7 +238,11 @@ sudo journalctl -u oral-trainer-api -f
当前上传后的处理任务运行在 API 进程中,因此只能使用一个 Uvicorn worker。需要多机或多 worker 时,应把 `VideoProcessor.process` 迁移到 Celery、RQ 或其他持久化任务队列。 当前上传后的处理任务运行在 API 进程中,因此只能使用一个 Uvicorn worker。需要多机或多 worker 时,应把 `VideoProcessor.process` 迁移到 Celery、RQ 或其他持久化任务队列。
## 4. 配置 NginxHTTPS ## 4. 配置 NginxHTTP 回源)
本机 Nginx 只监听 80 端口提供 HTTP不在本机终结 HTTPS。总出口线上边缘网关
`https://video_service.d1kt.cn` 终结 TLS 证书后,把请求以 HTTP 转发到本机
内网 IP 的 80 端口。因此本机不需要证书,也不需要安装 certbot。
```bash ```bash
sudo cp sentence_api/nginx.conf.example /etc/nginx/sites-available/oral-trainer sudo cp sentence_api/nginx.conf.example /etc/nginx/sites-available/oral-trainer
@@ -253,20 +257,24 @@ sudo systemctl reload nginx
- `proxy_request_buffering off`:上传时直接流向 FastAPI避免 Nginx 再完整缓存一份。 - `proxy_request_buffering off`:上传时直接流向 FastAPI避免 Nginx 再完整缓存一份。
- `proxy_force_ranges on`:保留 Android 随机拖动播放所需的 HTTP Range。 - `proxy_force_ranges on`:保留 Android 随机拖动播放所需的 HTTP Range。
- `proxy_read_timeout 7200s`:允许长视频处理和慢速上传。 - `proxy_read_timeout 7200s`:允许长视频处理和慢速上传。
- `X-Forwarded-Proto`透传边缘网关标记的原始协议https让 API 在需要时能识别
用户实际走的 HTTPS若网关不设置该头可把配置改回 `$scheme`
签发证书 本地验证(走本机 Nginx
```bash ```bash
sudo apt install -y certbot python3-certbot-nginx curl -H 'Host: video_service.d1kt.cn' http://127.0.0.1/healthz
sudo certbot --nginx -d video_service.d1kt.cn
``` ```
证书完成后验证: 公网验证(经总出口映射,需先在网关配置好 `https://video_service.d1kt.cn`
到本机内网 IP:80 的映射):
```bash ```bash
curl https://video_service.d1kt.cn/healthz curl https://video_service.d1kt.cn/healthz
``` ```
证书的申请与续期都在总出口完成,本机无需任何证书配置。
管理后台地址: 管理后台地址:
```text ```text

View File

@@ -78,5 +78,6 @@ model is connected.
python -m pytest sentence_api/tests -q python -m pytest sentence_api/tests -q
``` ```
See [DEPLOYMENT.md](DEPLOYMENT.md) for Docker, MOSS, Nginx, HTTPS, large-file See [DEPLOYMENT.md](DEPLOYMENT.md) for Docker, MOSS/Whisper, Nginx HTTP 回源,
large-file
upload, backup, and production operation instructions. upload, backup, and production operation instructions.

View File

@@ -1,3 +1,7 @@
# 本机 Nginx 只提供 HTTP端口 80不在本机终结 HTTPS
# 证书由“总出口”(线上边缘网关)终结,网关把 https://video_service.d1kt.cn
# 映射到本机内网 IP 的 80 端口,以 HTTP 回源。本机不需要证书,也不要监听 443。
server { server {
listen 80; listen 80;
server_name video_service.d1kt.cn; server_name video_service.d1kt.cn;
@@ -12,7 +16,8 @@ server {
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; # 透传边缘网关标记的原始协议https若网关不设置该头可改回 $scheme
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_request_buffering off; proxy_request_buffering off;
proxy_read_timeout 7200s; proxy_read_timeout 7200s;
proxy_send_timeout 7200s; proxy_send_timeout 7200s;