Files
2026-09-19 16:35:35 +08:00

133 lines
4.9 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#
# https://api.weiyuai.cn
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/letsencrypt/live/weiyuai.cn/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/weiyuai.cn/privkey.pem; # managed by Certbot
server_name api.weiyuai.cn;
# 直接将所有请求代理到Spring Boot
# X-Forwarded-Proto 必须下发:后端 AsrService#buildRelayWsUrl 依赖它决定 ws:// 还是 wss://
# 缺失会导致 HTTPS 站点拿到 ws:// 地址被浏览器按 Mixed Content 拦截
location / {
proxy_pass http://weiyuai;
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 fastcgi_params;
}
## 反向代理
# 实时语音识别中转 WebSocket(浏览器 HTTPS 页面必须走 wss)
location /ai/speech/realtime/relay {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://weiyuai;
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;
# 实时识别会话可能持续较长时间,放宽读写超时
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
include fastcgi_params;
}
## 反向代理
# 实时语音合成(TTS)中转 WebSocket
location /visitor/api/v1/tts/realtime {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://weiyuai;
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;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
include fastcgi_params;
}
## 反向代理
# 语音智能体(voice agentWebSocket,前缀匹配同时覆盖 /voice/ws 与 /voice/ws/audio
location /voice/ws {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://weiyuai;
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;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
include fastcgi_params;
}
## 反向代理
# https代理stomp连接
location /stomp {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://weiyuai/stomp;
# 为记录真实ip地址,而不是反向代理服务器地址
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 fastcgi_params;
}
## 反向代理
# https代理websocket连接
location /websocket {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://weiyuaiwss/websocket;
# 为记录真实ip地址,而不是反向代理服务器地址
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 fastcgi_params;
}
#增加两头部
add_header X-Via $server_addr;
add_header X-Cache $upstream_cache_status;
## 反向代理
location @springboot {
# 将nginx所有请求均跳转到9003端口
proxy_pass http://weiyuai;
# add_header Access-Control-Allow-Origin *; # 报错,不能添加,需要在spring boot中去掉相应的origin
# 为记录真实ip地址,而不是反向代理服务器地址
proxy_set_header Host $host;
# X-Real-IP 让日志的IP显示真实的客户端的IP
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 fastcgi_params;
# 设置缓存
# 为应答代码为200和302的设置缓存时间为10分钟,404代码缓存10分钟。
#proxy_cache webserver;
#proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 10m;
}
}