学生管理系统-07打包与上线

一、项目架构

vue的项目必须要进行打包,并部署在nginx服务器上的

二、vue的打包

1、修改vue.cofing.js文件

在该文件中添加publicPath属性,值为./

javascript 复制代码
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  publicPath:'./'
})

2、修改router/index.js文件

javascript 复制代码
const router=new VueRouter({
    routes,
    mode:'hash',
    base:'/studentMgr/'
})

3、打包

在终端上执行如下命令

javascript 复制代码
npm run build

打包之后,会在项目的根目录下产生一个叫dist的文件夹,这个就是打包之后的文件

三、项目上线部署

1、更改dist的名称

这里我将dist的名称改为studentMgr

2、通过xftp等上传工具,将这个文件上传到/opt/

3、修改nginx的配置文件

该配置文件在/etc/nginx/conf.d

使用编辑软件将default.conf文件打开

javascript 复制代码
location /studentMgr {
   alias /opt/studentMgr;
   index index.html;
}

4、重启nginx服务器

  • 通过xshell等命令行工具进入到linux

  • 查看nginx进程状态

javascript 复制代码
[root@iZ2ze9412d3dcresdj7soqZ ~]# ps aux|grep nginx
root      5379  0.0  0.0  46476  1036 ?        Ss   15:38   0:00 nginx: master process /usr/sbin/nginx
nginx     5380  0.0  0.1  46928  2148 ?        S    15:38   0:00 nginx: worker process
root      9627  0.0  0.0 112704   972 pts/2    S+   16:20   0:00 grep --color=auto nginx
  • 杀死nginx进程
javascript 复制代码
[root@iZ2ze9412d3dcresdj7soqZ ~]# killall -9 nginx
  • 启动nginx
javascript 复制代码
[root@iZ2ze9412d3dcresdj7soqZ ~]# /usr/sbin/nginx

5、history模式下404的解决办法

  • 在etc/nginx/default.d文件中将配置项上添加tryfiles属性,具体配置如下
javascript 复制代码
location /studentMgr {
        alias /opt/studentMgr;
        index index.html;
        try_files $uri $uri/ /studentMgr/index.html;
 }
相关推荐
知识分享小能手3 小时前
React学习教程,从入门到精通,React 组件核心语法知识点详解(类组件体系)(19)
前端·javascript·vue.js·学习·react.js·react·anti-design-vue
萌萌哒草头将军4 小时前
Oxc 和 Rolldown Q4 更新计划速览!🚀🚀🚀
javascript·vue.js·vite
Qlittleboy4 小时前
uniapp如何使用本身的字体图标
javascript·vue.js·uni-app
小白菜学前端5 小时前
vue2 常用内置指令总结
前端·vue.js
林_深时见鹿5 小时前
Vue + ElementPlus 自定义指令控制输入框只可以输入数字
前端·javascript·vue.js
椒盐螺丝钉5 小时前
Vue组件化开发介绍
前端·javascript·vue.js
koooo~5 小时前
v-model与-sync的演变和融合
前端·javascript·vue.js
xiaoyan20157 小时前
Electron38-Winchat聊天系统|vite7+electron38+vue3电脑端聊天Exe
vue.js·electron·vite
reembarkation7 小时前
vue-pdf 实现blob数据的预览
javascript·vue.js·pdf
给月亮点灯|8 小时前
Vue3基础知识-setup()、ref()和reactive()
前端·javascript·vue.js