Skip to content

SPA 模板

适合 Vue Router、React Router、Vite SPA 等前端路由应用。

替换:

  • example.com
  • /var/www/app/dist
nginx
server {
    listen 80;
    listen [::]:80;
    server_name example.com;

    root /var/www/app/dist;
    index index.html;

    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log;

    location / {
        try_files $uri $uri/ /index.html;
        add_header Cache-Control "no-store";
    }

    location ~* ^/(?:assets|static)/ {
        try_files $uri =404;
        access_log off;
        add_header Cache-Control "public, max-age=31536000, immutable";
    }

    location ~* \.(?:ico|txt|json|xml|webmanifest)$ {
        try_files $uri =404;
        access_log off;
        add_header Cache-Control "public, max-age=604800";
    }
}

try_files $uri $uri/ /index.html 用于处理前端路由刷新 404。

基于 MIT 许可发布