47 lines
1.2 KiB
Nginx Configuration File
47 lines
1.2 KiB
Nginx Configuration File
server {
|
|
listen 80;
|
|
server_name localhost;
|
|
|
|
# 根目录
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# 启用gzip压缩
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_min_length 1024;
|
|
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;
|
|
|
|
# 静态文件缓存
|
|
location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff|woff2|ttf|svg|eot)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
try_files $uri =404;
|
|
}
|
|
|
|
# SPA路由支持 - 所有非静态文件请求重定向到index.html
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
# 健康检查端点
|
|
location /health {
|
|
access_log off;
|
|
return 200 'healthy\n';
|
|
add_header Content-Type text/plain;
|
|
}
|
|
|
|
# API代理到后端服务
|
|
location /api {
|
|
proxy_pass http://backend:3001;
|
|
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_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
}
|
|
} |