# k3s 方案 A:仅静态 SPA。API 由浏览器按域名直连;TLS 由 Traefik 终结。 server { listen 80; server_name _; gzip on; gzip_vary on; gzip_min_length 1024; gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml image/svg+xml; root /usr/share/nginx/html; index index.html; # 官网静态(若存在);否则回退 SPA location = / { try_files /site/index.html /index.html =404; add_header Cache-Control "no-cache, no-store, must-revalidate"; add_header Pragma "no-cache"; add_header Expires "0"; } location = /site { return 301 /; } location = /site/ { return 301 /; } location = /site/index.html { return 301 /; } location ^~ /site/ { try_files $uri =404; expires 7d; add_header Cache-Control "public"; access_log off; } location = /favicon.ico { try_files /favicon.png /favicon.ico =404; expires 7d; add_header Cache-Control "public"; access_log off; } location = /index.html { add_header Cache-Control "no-cache, no-store, must-revalidate"; add_header Pragma "no-cache"; add_header Expires "0"; } # 微信域名校验文件 location ~* ^/MP_verify_[A-Za-z0-9]+\.txt$ { try_files $uri =404; add_header Cache-Control "no-cache"; } location ~* \.(?:js|css|woff2?|ttf|eot|svg|png|jpe?g|gif|webp|ico|map)$ { try_files $uri =404; expires 7d; add_header Cache-Control "public"; access_log off; } # SPA 路由回退 location / { try_files $uri $uri/ /index.html; } }