Vite构建的Vue3项目打包后dist文件夹放Nginx服务器访问添加上下文路径
Vue3项目打包后如何添加访问路径,vite.config.ts、Nginx如何配置
·
操作步骤
以访问路径端口号后面的上下文context为例子,最终的访问效果为:http:127.0.0.1:8098/context
1.vite.config.ts配置文件
base: '/context',
2. 路由配置文件
const router = createRouter({
history: createWebHistory('/context/'), // 与步骤1中的保持一致(注意斜杠)
routes
})
3. Nginx配置文件
- 假设build后的静态文件夹采用默认的名称:dist
- 假设dist文件存放在Nginx服务器上的目录:/usr/local/nginx/www
- 假设访问的端口为:8098
基于以上假设,则重启nginx后访问的路径为:
http:127.0.0.1:8098/context
server {
listen 8098;
charset utf-8;
location /context {
alias /usr/local/nginx/www/dist;
index index.html;
try_files $uri $uri/ /index.html last;
}
# 下面的为Vue应用访问接口的配置(不受上下文的影响)
location /xxx {
proxy_pass http://ip:port;
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)