ai_learn_node/nginx/nginx.conf.example

59 lines
1.7 KiB
Plaintext
Raw Normal View History

2026-01-13 02:58:12 +00:00
# Nginx 配置示例文件
# 复制此文件并根据您的环境修改配置
# 上游后端服务器
upstream backend {
server localhost:3001; # 修改为您的后端服务器地址
keepalive 64;
}
server {
listen 80;
2026-01-13 03:30:53 +00:00
server_name _; # 使用 IP 访问_ 表示匹配所有域名和 IP
2026-01-13 02:58:12 +00:00
# 客户端最大请求体大小
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;
}
}