60 lines
1.6 KiB
Docker
60 lines
1.6 KiB
Docker
|
|
# Nginx 配置文件 - Docker 部署版本
|
||
|
|
# 用于 docker-compose 部署,使用 Docker 服务名进行服务发现
|
||
|
|
|
||
|
|
# 上游后端服务器(使用 Docker 服务名)
|
||
|
|
upstream backend {
|
||
|
|
server backend:3001; # 使用 Docker Compose 服务名
|
||
|
|
keepalive 64;
|
||
|
|
}
|
||
|
|
|
||
|
|
# HTTP 服务器配置
|
||
|
|
server {
|
||
|
|
listen 80;
|
||
|
|
server_name _; # 匹配所有域名和 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 /usr/share/nginx/html;
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
}
|