vue项目中得vue-router使用得是history
const router = createRouter({
history: createWebHistory('/wwj'), //指定得基本路径为 /wwj
routes, // `routes: routes` 的缩写
})
服务器静态页面文件放在/www/blogs/wwj/
http://www.wewewew.cn 指定文件夹/www/blogs
打包好的vue项目在wwj中,所以需要http://www.wewewew.cn/wwj/ 访问wwj下得index.htm
server
{
listen 80; #监听端口
server_name www.wewewew.cn wewewew.cn;
index index.php index.html index.htm default.php default.htm default.html;
root /www/blogs/;
# vue项目默认得根路径 http://www.wewewew.cn/wwj/
location /wwj/
{
#alias属性指定的值不需要加入到最终路径中
alias /www/blogs/wwj/;
# 默认打开得文件
index index.html;
# try_files $uri $uri/ /index.html; 告诉nginx如果按顺序检查文件是否存在,若不存在则重定向到index.html文件
try_files $uri $uri/ /index.html last;
# 跳转得404页面 history中自定义得404路由
error_page 404 /404;
}
# 全局得404页面
error_page 404 /404.html;
location = 404.html {
root /www/blogs/404.html;
}
}