81 lines
2.3 KiB
Nginx Configuration File
81 lines
2.3 KiB
Nginx Configuration File
# Nginx配置示例 - AI Pet Companion
|
||
# 用于部署到服务器 8.152.169.84
|
||
|
||
server {
|
||
listen 80;
|
||
server_name 8.152.169.84;
|
||
|
||
# 前端静态文件
|
||
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;
|
||
# } |