fix:优化整个项目
This commit is contained in:
102
docs/nginx-view.airtep.com-完整示例.conf
Normal file
102
docs/nginx-view.airtep.com-完整示例.conf
Normal file
@@ -0,0 +1,102 @@
|
||||
# view.airtep.com 完整 server 配置示例(80+443 合一,/api 反代 5599)
|
||||
# 在宝塔 → 网站 → view.airtep.com → 设置 → 配置文件 中,用本文件内容替换整个 server { } 块后保存,再 nginx -t && nginx -s reload
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
listen 443 ssl http2;
|
||||
server_name view.airtep.com;
|
||||
index index.php index.html index.htm default.php default.htm default.html;
|
||||
root /www/wwwroot/view.airtep.com/dist/;
|
||||
|
||||
#CERT-APPLY-CHECK--START
|
||||
include /www/server/panel/vhost/nginx/well-known/view.airtep.com.conf;
|
||||
#CERT-APPLY-CHECK--END
|
||||
include /www/server/panel/vhost/nginx/extension/view.airtep.com/*.conf;
|
||||
|
||||
#SSL-START
|
||||
ssl_certificate /www/server/panel/vhost/cert/view.airtep.com/fullchain.pem;
|
||||
ssl_certificate_key /www/server/panel/vhost/cert/view.airtep.com/privkey.pem;
|
||||
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
|
||||
ssl_prefer_server_ciphers on;
|
||||
ssl_session_tickets on;
|
||||
ssl_session_cache shared:SSL:10m;
|
||||
ssl_session_timeout 10m;
|
||||
add_header Strict-Transport-Security "max-age=31536000";
|
||||
error_page 497 https://$host$request_uri;
|
||||
#SSL-END
|
||||
|
||||
#ERROR-PAGE-START
|
||||
error_page 404 /404.html;
|
||||
#ERROR-PAGE-END
|
||||
|
||||
#PHP-INFO-START
|
||||
include enable-php-00.conf;
|
||||
#PHP-INFO-END
|
||||
|
||||
#REWRITE-START
|
||||
include /www/server/panel/vhost/rewrite/view.airtep.com.conf;
|
||||
#REWRITE-END
|
||||
|
||||
# ---------- 先配路由与反代,再配禁止规则 ----------
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /api {
|
||||
proxy_pass http://127.0.0.1:5599/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location = /edit {
|
||||
try_files /index.html =404;
|
||||
}
|
||||
|
||||
location /ws {
|
||||
proxy_pass http://127.0.0.1:3003;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection $connection_upgrade;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_read_timeout 86400;
|
||||
}
|
||||
|
||||
# 禁止访问的敏感文件(不含 api.config.json、config.json)
|
||||
location ~* (\.user\.ini|\.htaccess|\.htpasswd|\.env.*|\.project|\.bashrc|\.bash_profile|\.bash_logout|\.DS_Store|\.gitignore|\.gitattributes|LICENSE|README\.md|CLAUDE\.md|CHANGELOG\.md|CHANGELOG|CONTRIBUTING\.md|TODO\.md|FAQ\.md|composer\.json|composer\.lock|package(-lock)?\.json|yarn\.lock|pnpm-lock\.yaml|\.\w+~|\.swp|\.swo|\.bak(up)?|\.old|\.tmp|\.temp|\.log|\.sql(\.gz)?|docker-compose\.yml|docker\.env|Dockerfile|\.csproj|\.sln|Cargo\.toml|Cargo\.lock|go\.mod|go\.sum|phpunit\.xml|pom\.xml|build\.gradl|pyproject\.toml|requirements\.txt|application(-\w+)?\.(ya?ml|properties))$
|
||||
{
|
||||
return 404;
|
||||
}
|
||||
|
||||
location ~* /(\.git|\.svn|\.bzr|\.vscode|\.claude|\.idea|\.ssh|\.github|\.npm|\.yarn|\.pnpm|\.cache|\.husky|\.turbo|\.next|\.nuxt|node_modules|runtime)/ {
|
||||
return 404;
|
||||
}
|
||||
|
||||
location ~ \.well-known {
|
||||
allow all;
|
||||
}
|
||||
|
||||
if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
|
||||
return 403;
|
||||
}
|
||||
|
||||
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
|
||||
expires 30d;
|
||||
error_log /dev/null;
|
||||
access_log /dev/null;
|
||||
}
|
||||
|
||||
location ~ .*\.(js|css)?$ {
|
||||
expires 12h;
|
||||
error_log /dev/null;
|
||||
access_log /dev/null;
|
||||
}
|
||||
|
||||
access_log /www/wwwlogs/view.airtep.com.log;
|
||||
error_log /www/wwwlogs/view.airtep.com.error.log;
|
||||
}
|
||||
19
docs/nginx-view.airtep.com-必加.conf
Normal file
19
docs/nginx-view.airtep.com-必加.conf
Normal file
@@ -0,0 +1,19 @@
|
||||
# view.airtep.com 必须有的两段配置(避免 404)
|
||||
# 在宝塔 → 网站 → view.airtep.com → 设置 → 配置文件 中,
|
||||
# 在 server { } 内、且不要有重复或冲突的 location /api 或 location /api/ 。
|
||||
# 只保留下面这一种 /api 反代,删掉任何 proxy_pass 到 3003 或别的端口的 location /api/ 。
|
||||
|
||||
# 1) 把 /api 开头的请求转到本机 5599(本项目 API)
|
||||
location /api {
|
||||
proxy_pass http://127.0.0.1:5599/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# 2) 若 api.config.json 被「禁止访问」规则误拦,可加下面这段(二选一,一般 root 正确即可)
|
||||
# location = /api.config.json {
|
||||
# alias /www/wwwroot/view.airtep.com/dist/api.config.json;
|
||||
# }
|
||||
86
docs/前端与接口关系说明.md
Normal file
86
docs/前端与接口关系说明.md
Normal file
@@ -0,0 +1,86 @@
|
||||
# 前端与接口关系说明
|
||||
|
||||
## 一、架构关系
|
||||
|
||||
```
|
||||
浏览器访问 https://view.airtep.com
|
||||
│
|
||||
▼
|
||||
Nginx (80/443)
|
||||
│
|
||||
├─ / → root dist/ → index.html、config.json、api.config.json、lib/、image/
|
||||
├─ /api/* → 反代到 127.0.0.1:5599/ → 后端 Node(无 /api 前缀)
|
||||
└─ 其他静态 → dist/ 下文件
|
||||
```
|
||||
|
||||
- **前端**:纯静态,来自 `dist/`(index.html、config.json、api.config.json、lib/、image/)。由 Nginx 的 `root` + `location /` 提供。
|
||||
- **接口**:Node 进程监听 **5599**,路由为 **/config、/stats、/view、/join、/comments** 等(**没有 /api 前缀**)。
|
||||
- **Nginx 反代**:必须用 `location /api` 且 `proxy_pass http://127.0.0.1:5599/;`(末尾有 `/`),这样请求 `/api/config` 会被转成后端的 `/config`。
|
||||
|
||||
## 二、为何出现 404
|
||||
|
||||
`nginx -T` 里会看到**多个** `location /api` 和 **location /api/**,来自不同站点或 include:
|
||||
|
||||
- **location /api**(4 个字符)→ 反代到 5599 ✅
|
||||
- **location /api/**(5 个字符)→ 可能反代到 3000、3001、9091 等 ❌
|
||||
|
||||
Nginx 对**前缀 location** 选**最长匹配**。请求 `/api/config` 时,若当前 server 里**同时存在** `location /api` 和 `location /api/`,会匹配到 **location /api/**。若这个 `/api/` 指向的是 3001 等其它服务,就会返回 404。
|
||||
|
||||
因此:**view.airtep.com 的 server 里只能保留「反代到 5599」的那一个 location,且不要有「location /api/」指向其它端口。**
|
||||
|
||||
## 三、正确配置(view.airtep.com 仅此一段 /api)
|
||||
|
||||
在 view.airtep.com 的 server 块内:
|
||||
|
||||
- **只保留**下面这一段,**不要**再写 `location /api/` 或其它端口的 `/api`:
|
||||
|
||||
```nginx
|
||||
location /api {
|
||||
proxy_pass http://127.0.0.1:5599/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
```
|
||||
|
||||
- 若存在 **include**(例如 `extension/view.airtep.com/*.conf`),检查这些 conf 里是否带有 **location /api/** 或 **location /api**。若有且指向 3000/3001/9091 等,要在 view.airtep.com 的站点下**删掉或注释**这些 include 中的 `/api` 配置,或在该 include 里**只保留**上面这段 5599 反代。
|
||||
|
||||
## 四、检查与验证
|
||||
|
||||
在服务器上:
|
||||
|
||||
```bash
|
||||
# 1. 本机 API 正常
|
||||
curl -s http://127.0.0.1:5599/config
|
||||
# 应返回:{"danmakuEnabled":false,"danmakuPosition":"top"}
|
||||
|
||||
# 2. 查看 view.airtep.com 所在 server 块中的 /api 配置(行号供对照)
|
||||
grep -n "location /api\|proxy_pass" /www/server/panel/vhost/nginx/view.airtep.com.conf
|
||||
|
||||
# 3. 查看是否有 extension 覆盖 /api
|
||||
ls /www/server/panel/vhost/nginx/extension/view.airtep.com/
|
||||
cat /www/server/panel/vhost/nginx/extension/view.airtep.com/*.conf
|
||||
|
||||
# 4. 重载后测 80 和 443
|
||||
nginx -t && nginx -s reload
|
||||
curl -s -o /dev/null -w "80: %{http_code}\n" "http://127.0.0.1/api/config" -H "Host: view.airtep.com"
|
||||
curl -sk -o /dev/null -w "443: %{http_code}\n" "https://view.airtep.com/api/config"
|
||||
# 两者都应为 200
|
||||
```
|
||||
|
||||
## 五、后端数据落库与前端显示
|
||||
|
||||
- **存储**:后端使用 `server/data/store.json`(JSON 文件),路径由 `server/db.js` 的 `__dirname` 决定,与进程当前工作目录无关;每次修改(浏览/点赞/分享/加入离开/评论)都会调用 `save()` 落盘。
|
||||
- **验证落库**:在服务器上查看 `server/data/store.json` 或请求 `curl -s http://127.0.0.1:5599/stats` 即可确认数据是否写入。
|
||||
- **前端显示异常**:若接口正常但页面上的「播放次数、点赞、分享、评论、在看」出现被置 0 或错乱,多为前端用「部分接口返回值」直接刷新整块统计导致(例如 `/join` 只返回 `watchingNow`,却用 `updateStatsUI({ watchingNow })` 把其他项也刷成 0)。处理方式:前端维护一份 `lastStats`,每次只合并本次接口返回的字段再刷新 UI,避免部分更新覆盖其它统计。
|
||||
|
||||
## 六、小结
|
||||
|
||||
| 角色 | 说明 |
|
||||
|------------|------|
|
||||
| 前端 | Nginx 提供 dist/ 下静态资源,同域访问。 |
|
||||
| 接口 | Node 监听 5599,路由为 /config、/stats 等(无 /api 前缀)。 |
|
||||
| Nginx 反代 | 仅用 **location /api** 且 **proxy_pass http://127.0.0.1:5599/**,且本站点内不要有 **location /api/** 指向其它端口。 |
|
||||
| 404 原因 | 存在 **location /api/** 且指向 3001 等,优先于 **location /api**,请求被转到错误后端。 |
|
||||
Reference in New Issue
Block a user