server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.html; # SPA 路由支持 - 所有路径都返回 index.html location / { try_files $uri $uri/ /index.html; } # Markdown 接口说明,直接返回文本内容 location = /apidoc { types { } default_type text/plain; charset utf-8; try_files /apidoc =404; add_header Cache-Control "no-store"; } # 知识库静态 JSON API,接口路径不存在时返回 404,避免被 SPA 回退到 index.html location /api/ { try_files $uri =404; add_header Cache-Control "no-store"; } # 一图流图片文件缓存 30 天;新增图片建议使用新文件名,避免同名覆盖缓存未刷新 location ~* ^/learning-images/.+\.(png|jpg|jpeg|webp|gif|avif)$ { root /usr/share/nginx/html; expires 30d; add_header Cache-Control "public, max-age=2592000"; } # 一图流图片目录,由 Docker 挂载提供;目录列表不缓存,保证新增图片能及时被页面发现 location /learning-images/ { alias /usr/share/nginx/html/learning-images/; autoindex on; charset utf-8; add_header Cache-Control "no-store"; } # 静态资源缓存 location /assets { expires 1y; add_header Cache-Control "public, immutable"; } # gzip 压缩 gzip on; gzip_types text/plain text/css application/json application/javascript text/xml application/xml; gzip_min_length 1000; }