Files
lab/frontend/nginx.conf
2026-09-21 12:51:08 +08:00

36 lines
1.0 KiB
Nginx Configuration File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Nginx 站点配置:SPA 路由回退 + /api 反向代理到后端容器
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# 静态资源压缩
gzip on;
gzip_min_length 1k;
gzip_types text/plain text/css application/javascript application/json image/svg+xml;
# 前端单页应用:刷新子路由时回退到 index.html
location / {
try_files $uri $uri/ /index.html;
}
# 后端接口:转发到 docker-compose 中的 backend 服务
location /api/ {
proxy_pass http://backend:8080;
proxy_http_version 1.1;
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_read_timeout 60s;
}
# 带哈希的静态资源长期缓存
location /assets/ {
expires 7d;
add_header Cache-Control "public, max-age=604800";
}
}