Skip to content
宝塔发版vite项目

打包

vite.config.js 的baseUrl 改为 /

npm run build

把dist目录下的文件上传到服务器的htdocs目录下

绑定域名运行站点

发现404

找到php项目

找到当前站点

点击右边的设置

找到配置文件

在location配置最下面追加两个location配置

js
location / {
    # 尝试直接访问文件($uri)→ 尝试访问目录($uri/)→ 最后回退到 index.html
    try_files $uri $uri/ /index.html;
}
    
    # 匹配所有静态资源(JS/CSS/图片等),并设置缓存
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
    expires 30d;          # 缓存30天,优化性能
    add_header Cache-Control "public";
    access_log off;       # 关闭访问日志,减少 IO
    # 确保 root 指向正确的目录(你的文件在 /www/wwwroot/books)
    root /www/wwwroot/books;
    # 如果资源在子目录(如 assets),Nginx 会自动拼接路径(如 /assets/xxx.js → /www/wwwroot/books/assets/xxx.js)
}

然后再访问就可以了