ai_learn_node/nginx/nginx.conf

128 lines
3.6 KiB
Nginx Configuration File
Raw Normal View History

2026-01-13 02:58:12 +00:00
# Nginx 配置文件 - AI学习平台
# 上游后端服务器
upstream backend {
server localhost:3001;
keepalive 64;
}
# HTTP 服务器配置
server {
listen 80;
server_name localhost; # 修改为您的域名
# 客户端最大请求体大小
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 /var/www/ai-learning-platform/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;
}
}
# HTTPS 服务器配置(可选,需要 SSL 证书)
# server {
# listen 443 ssl http2;
# server_name localhost; # 修改为您的域名
#
# # SSL 证书配置
# ssl_certificate /path/to/your/certificate.crt;
# ssl_certificate_key /path/to/your/private.key;
#
# # SSL 优化配置
# ssl_protocols TLSv1.2 TLSv1.3;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# ssl_session_cache shared:SSL:10m;
# ssl_session_timeout 10m;
#
# # 客户端最大请求体大小
# client_max_body_size 10M;
#
# # 日志配置
# access_log /var/log/nginx/ai-learning-ssl-access.log;
# error_log /var/log/nginx/ai-learning-ssl-error.log;
#
# # 前端静态文件
# location / {
# root /var/www/ai-learning-platform/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;
# }
# }
#
# # HTTP 重定向到 HTTPS
# server {
# listen 80;
# server_name localhost; # 修改为您的域名
# return 301 https://$server_name$request_uri;
# }