84 lines
2.6 KiB
Nginx Configuration File
84 lines
2.6 KiB
Nginx Configuration File
server {
|
|
listen 80;
|
|
server_name localhost;
|
|
|
|
# Gzip 压缩配置
|
|
gzip on;
|
|
gzip_min_length 1k;
|
|
gzip_comp_level 6;
|
|
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
|
|
gzip_vary on;
|
|
gzip_disable "MSIE [1-6]\.";
|
|
|
|
# API 代理到后端(不带项目路径前缀)
|
|
location /prod-api/ {
|
|
proxy_pass http://backend:8888/;
|
|
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 600;
|
|
proxy_read_timeout 600;
|
|
proxy_send_timeout 600;
|
|
|
|
# 支持 WebSocket
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
}
|
|
|
|
# 前端静态文件路径(带项目路径前缀)
|
|
location /ashai-wecom-test {
|
|
alias /usr/share/nginx/html/ashai-wecom-test;
|
|
try_files $uri $uri/ /ashai-wecom-test/index.html;
|
|
index index.html;
|
|
|
|
# 静态资源缓存配置
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
expires 7d;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
}
|
|
|
|
# API 代理到后端(带项目路径前缀)
|
|
location /ashai-wecom-test/prod-api/ {
|
|
proxy_pass http://backend:8888/;
|
|
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 600;
|
|
proxy_read_timeout 600;
|
|
proxy_send_timeout 600;
|
|
|
|
# 支持 WebSocket
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
}
|
|
|
|
# 根路径重定向到项目路径
|
|
location = / {
|
|
return 301 /ashai-wecom-test/;
|
|
}
|
|
|
|
# 其他所有路径都尝试从项目目录加载(支持 Vue Router History 模式)
|
|
location / {
|
|
root /usr/share/nginx/html/ashai-wecom-test;
|
|
try_files $uri $uri/ /index.html;
|
|
index index.html;
|
|
|
|
# 静态资源缓存配置
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
expires 7d;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
}
|
|
|
|
# 错误页面
|
|
error_page 500 502 503 504 /50x.html;
|
|
location = /50x.html {
|
|
root /usr/share/nginx/html;
|
|
}
|
|
}
|