server {
    listen 80;
    server_name localhost;

    # 静态资源缓存
    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?|map)$ {
        root /usr/share/nginx/html;
        expires 7d;
        add_header Cache-Control "public, immutable";
    }

    # 前端 SPA — 静态文件存在则返回，不存在则转发到后端
    location / {
        root   /usr/share/nginx/html;
        index  index.html;
        try_files $uri $uri/ @backend;
    }

    # 后端接口反代到本机 Docker 内的 Web 容器
    location @backend {
        proxy_pass http://web:8080;
        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_connect_timeout 60s;
        proxy_read_timeout 120s;
    }
}
