2026-04-12 11:32:37 +08:00
|
|
|
|
# Nginx配置示例 - AI Pet Companion
|
|
|
|
|
|
# 用于部署到服务器 8.152.169.84
|
|
|
|
|
|
|
|
|
|
|
|
server {
|
|
|
|
|
|
listen 80;
|
|
|
|
|
|
server_name 8.152.169.84;
|
2026-05-23 15:24:27 +08:00
|
|
|
|
client_max_body_size 1024m;
|
2026-04-12 11:32:37 +08:00
|
|
|
|
|
|
|
|
|
|
# 前端静态文件
|
|
|
|
|
|
location / {
|
|
|
|
|
|
root /path/to/your/frontend/dist;
|
|
|
|
|
|
index index.html;
|
|
|
|
|
|
try_files $uri $uri/ /index.html;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# API代理到后端
|
|
|
|
|
|
location /api/ {
|
|
|
|
|
|
proxy_pass http://localhost:8001;
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
# WebSocket支持
|
|
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
|
|
|
|
proxy_set_header Connection "upgrade";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# WebSocket连接
|
|
|
|
|
|
location /ws/ {
|
|
|
|
|
|
proxy_pass http://localhost:8001;
|
|
|
|
|
|
proxy_http_version 1.1;
|
|
|
|
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
|
|
|
|
proxy_set_header 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_set_header X-Forwarded-Proto $scheme;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# 上传文件访问
|
|
|
|
|
|
location /uploads/ {
|
|
|
|
|
|
proxy_pass http://localhost:8001;
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# 错误页面
|
|
|
|
|
|
error_page 404 /404.html;
|
|
|
|
|
|
error_page 500 502 503 504 /50x.html;
|
|
|
|
|
|
|
|
|
|
|
|
location = /50x.html {
|
|
|
|
|
|
root /usr/share/nginx/html;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# HTTPS配置示例 (如果需要SSL)
|
|
|
|
|
|
# server {
|
|
|
|
|
|
# listen 443 ssl;
|
|
|
|
|
|
# server_name 8.152.169.84;
|
|
|
|
|
|
#
|
|
|
|
|
|
# ssl_certificate /path/to/your/certificate.crt;
|
|
|
|
|
|
# ssl_certificate_key /path/to/your/private.key;
|
|
|
|
|
|
#
|
|
|
|
|
|
# # 其他配置同上...
|
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
|
|
# WebSocket测试配置
|
|
|
|
|
|
# 如果遇到WebSocket连接问题,可以尝试添加这些配置:
|
|
|
|
|
|
#
|
|
|
|
|
|
# location /api/v1/voice/realtime/ {
|
|
|
|
|
|
# proxy_pass http://localhost:8001;
|
|
|
|
|
|
# proxy_http_version 1.1;
|
|
|
|
|
|
# proxy_set_header Upgrade $http_upgrade;
|
|
|
|
|
|
# proxy_set_header Connection "upgrade";
|
|
|
|
|
|
# proxy_set_header Host $host;
|
|
|
|
|
|
# proxy_read_timeout 86400;
|
|
|
|
|
|
# proxy_send_timeout 86400;
|
|
|
|
|
|
# }
|