# 供 compose 中 web 容器使用：与 deploy/web/default.conf 同步；验证文件仅外层 yh_nginx 处理
server {
    listen 80;
    root /usr/share/nginx/html;
    index index.html;

    location ^~ /assets/ {
        try_files $uri =404;
        access_log off;
        expires 7d;
        add_header Cache-Control "public, immutable";
    }

    location = /index.html {
        add_header Cache-Control "no-cache, no-store, must-revalidate";
        expires -1;
    }

    # web/public 挂载 /var/www/yh-public；单段文件名同 dist 根 URL，优先挂载后回退 dist
    location ~ ^/([^/]+\.(?:png|jpe?g|gif|ico|svg|webp|webmanifest))$ {
        root /var/www/yh-public;
        try_files /$1 @dist_root_public;
        expires 7d;
        add_header Cache-Control "public, max-age=604800";
    }
    location @dist_root_public {
        root /usr/share/nginx/html;
        try_files $uri =404;
        expires 7d;
        add_header Cache-Control "public, max-age=604800";
    }

    location ^~ /social/ {
        alias /var/www/yh-public/social/;
        expires 7d;
        add_header Cache-Control "public, max-age=604800";
    }

    location ^~ /promotion/ {
        try_files $uri =404;
        expires 7d;
        add_header Cache-Control "public, max-age=604800";
    }

    location = / {
        try_files /index.html =404;
    }
    # 前台为 Vue SPA：任意路径须回退到 index.html，否则直接访问 /xxx 会得到 nginx 404
    location / {
        try_files $uri $uri/ /index.html;
    }
}
