59 lines
1.7 KiB
Plaintext
59 lines
1.7 KiB
Plaintext
|
|
# Nginx 配置示例文件
|
||
|
|
# 复制此文件并根据您的环境修改配置
|
||
|
|
|
||
|
|
# 上游后端服务器
|
||
|
|
upstream backend {
|
||
|
|
server localhost:3001; # 修改为您的后端服务器地址
|
||
|
|
keepalive 64;
|
||
|
|
}
|
||
|
|
|
||
|
|
server {
|
||
|
|
listen 80;
|
||
|
|
server_name your-domain.com; # 修改为您的域名或 IP
|
||
|
|
|
||
|
|
# 客户端最大请求体大小
|
||
|
|
client_max_body_size 10M;
|
||
|
|
|
||
|
|
# 日志配置(可选)
|
||
|
|
# access_log /var/log/nginx/ai-learning-access.log;
|
||
|
|
# error_log /var/log/nginx/ai-learning-error.log;
|
||
|
|
|
||
|
|
# 前端静态文件路径(修改为实际路径)
|
||
|
|
location / {
|
||
|
|
root /path/to/frontend/dist; # 修改为前端构建文件的实际路径
|
||
|
|
index index.html;
|
||
|
|
try_files $uri $uri/ /index.html;
|
||
|
|
|
||
|
|
# 静态资源缓存
|
||
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
||
|
|
expires 1y;
|
||
|
|
add_header Cache-Control "public, immutable";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
# API 代理
|
||
|
|
location /api {
|
||
|
|
proxy_pass http://backend;
|
||
|
|
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;
|
||
|
|
proxy_cache_bypass $http_upgrade;
|
||
|
|
|
||
|
|
# 超时设置
|
||
|
|
proxy_connect_timeout 60s;
|
||
|
|
proxy_send_timeout 60s;
|
||
|
|
proxy_read_timeout 60s;
|
||
|
|
}
|
||
|
|
|
||
|
|
# 健康检查
|
||
|
|
location /health {
|
||
|
|
access_log off;
|
||
|
|
return 200 "healthy\n";
|
||
|
|
add_header Content-Type text/plain;
|
||
|
|
}
|
||
|
|
}
|