项目打包

在项目目录下执行打包目录进行打包

yarn build
// 或者
npm run build

打包完成后会生成一个dist文件夹,这样就打包完成了(我这样做了SEO的,所有目录结构有点不一样,但是整体都是差不多的)

nginx安装

下载 nginx

解压安装

将下载的nginx上传到服务器,运行以下命令执行解压安装

[root@VM-4-13-centos website]# tar -zxvf nginx-1.22.0.tar.gz				# 解压nginx
[root@VM-4-13-centos website]# cd nginx-1.22.0/ # 进入目录
[root@VM-4-13-centos nginx-1.22.0]# ./configure && make && make install # 安装

这样nginx就安装完成了,将刚打包的文件上传到/usr/local/nginx/目录中

进入安装目录,执行启动命令就可以启动nginx

[root@VM-4-13-centos nginx-1.22.0]# cd /usr/local/nginx/					# 进入安装目录
[root@VM-4-13-centos nginx]# ./sbin/nginx -c ./conf/nginx.conf # 启动nginx

这样就可以在浏览器输入IP:端口进行访问了,但是有的需要手动开启端口或关闭防火墙(两个只要执行一个就可以了)

./sbin/nginx 启动

./sbin/nginx -s stop 关闭

./sbin/nginx -s reload 重启

1.开启端口

[root@VM-4-13-centos ~]# firewall-cmd --permanent --add-port=80/tcp	   # 放开端口
[root@VM-4-13-centos ~]# firewall-cmd --permanent --add-port=443/tcp
[root@VM-4-13-centos ~]# firewall-cmd --reload # 重载防火墙

2.关闭防火墙

[root@VM-4-13-centos ~]# systemctl status firewalld.service    # 查看防火墙状态 ( 绿的running表示防火墙开启 )
[root@VM-4-13-centos ~]# systemctl stop firewalld.service # 执行关闭命令
[root@VM-4-13-centos ~]# systemctl status firewalld.service # 再次执行查看防火墙命令
[root@VM-4-13-centos ~]# systemctl disable firewalld.service # 执行开机禁用防火墙自启命令

nginx配置

我们需要配置端口号、请求的代理转发等,这里我主要就加了一个代理

[root@VM-4-13-centos conf]# cd /usr/local/nginx/conf	# 进入nginx的conf目录
[root@VM-4-13-centos conf]# vim nginx.conf # 编辑配置文件 server {
listen 80; # 端口号
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
}
# 拦截的上下文路径
location /website/ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'POST,GET,PUT,PATCH,DELETE,OPTIONS';
add_header Access-Control-Allow-Headers 'Content-Type, X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Date, X-Api-Version, X-File-Name,Token,Cookie,authorization';
# 转发到后端的地址
proxy_pass http://127.0.0.1:8081/website/;
}
}

修改完成后重启nginx服务,在页面上就可以看到请求能够正常的访问了;

当我们刷新页面的时候,或者访问路由配置页面的时候会直接404,这是因为通常我们做的vue项目属于单页面开发。所以只有index.html。解决这个bug也很简单。只需要将访问重定向到index.html这个页面。交由 index.html 去处理对应的路由跳转就好.

		location / {
alias html/;
index index.html index.htm;
try_files $uri $uri/ @router; # 需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404
} location /website/ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'POST,GET,PUT,PATCH,DELETE,OPTIONS';
add_header Access-Control-Allow-Headers 'Content-Type, X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Date, X-Api-Version, X-File-Name,Token,Cookie,authorization';
proxy_pass http://127.0.0.1:8081/website/;
}
# 对应上面的@router,主要原因是路由的路径资源并不是一个真实的路径,所以无法找到具体的文件
# 因此需要rewrite到index.html中,然后交给路由在处理请求资源
location @router {
rewrite ^.*$ /index.html last;
}

修改完成后重启nginx服务,这样就没有问题了(配置下面的内容记得先把 nginx 停掉)

注册为服务

每次开机都需要去手动启动就会很麻烦,如果将nginx注册为服务,设置为开机自启的状态,每次开机服务就会自动启动

创建nginx.service文件

[root@VM-4-13-centos ~]# vim /lib/systemd/system/nginx.service

加入下面的内容

[Unit]
#描述服务
Description=nginx
#描述服务类别
After=network.target #服务运行参数的设置,注意【Service】的启动、重启、停止命令都要用绝对路径
[Service]
#后台运行的形式
Type=forking
#服务具体运行的命令
ExecStart=/usr/local/nginx/sbin/nginx
#重启命令
ExecReload=/usr/local/nginx/sbin/nginx -s reload
#停止命令
ExecStop=/usr/local/nginx/sbin/nginx -s quit
#表示给服务分配独立的临时空间
PrivateTmp=true #运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
[Install]
WantedBy=multi-user.target

完成后保存退出

设置开机启动

[root@VM-4-13-centos ~]# systemctl enable nginx.service

其它命令

systemctl start nginx.service    #启动nginx服务
systemctl stop nginx.service #停止nginx服务
systemctl restart nginx.service #重新启动服务
systemctl enable nginx.service #设置开机自启动
systemctl disable nginx.service #停止开机自启动
systemctl status nginx.service #查看服务当前状态
systemctl list-units --type=service #查看所有已启动的服务

Vue打包部署到CentOS 7的更多相关文章

  1. Vue 打包部署上线

    1,VUE逻辑编写完成后在当前项目下打包 npm run build 需要注意的是,当打包完毕后,需要将入口的index.html的项目dist路径改成相对路径 另外需要注意的一点是,一旦打包vue. ...

  2. vue 打包部署到服务器上 配置nginx访问

    坑一 css,js资源引入不正确 webpack配置文件config/index.js 需要更改: 方法一 当部署到带有文件夹的项目中,这种绝对路径就会出现问题,因为把配置的static文件夹当成了根 ...

  3. vue打包部署(含2.0)

    到这里vue的所有平时使用的知识点都写完了 先补充一下vue2.x的安装 ## 全局脚手架 npm install vue/cli -g ## 查看版本 vue --version ## 新建项目 v ...

  4. -webkit-line-clamp、-webkit-box-orient vue 打包部署后不起作用??

    场景分析:实际开发中,文字描述过长,需要两行或三行显示缩略显示: 实现过程: 实现过程遇到的问题:打包到线上后发现并没有-webkit-box-orient属性,导致省略号并没有按预期展示: 解决方法 ...

  5. Vue 打包部署到服务器后,非主页刷新后出现404问题解决

    开心把项目部署到服务上,从头到尾点了一遍,发现没有问题,以为就可以大功告成,没想到刷新页面时出现 被破泼了一脸的凉水,更奇怪的事首页没有问题,只有其他页面出现,在调戏了很久的度娘后,才从坑里跳出来,以 ...

  6. vue项目 打包部署上线

    1. npm run dev:本地开发的时候做调试用的. 2. npm run build:打包部署上线,生成一个 dist 文件夹. 注意:用 npm run build 时,常遇到因引用路径不对导 ...

  7. Vue+elementUI build打包部署后字体图标丢失问题

    错误描述:Vue+elementUI  build打包部署后字体图标丢失,控制台显示文件element-icons.woff和element-icons.ttf文件404 错误展现: 控制台报错截图 ...

  8. vue-multi-module【多模块集成的vue项目,多项目共用一份配置,可以互相依赖,也可以独立打包部署】

    基于 vue-cli 2 实现,vue 多模块.vue多项目集成工程 Github项目地址 : https://github.com/BothEyes1993/vue-multi-module 目标: ...

  9. vue项目打包部署到nginx 服务器上

    假如要实现的效果如下 http://ip/vue    =>是进入首页访问的路径是  usr/local/nginx/html/vue http://ip/website     =>是进 ...

  10. 阿里云安装Nginx+vue项目部署

    阿里云安装Nginx+vue项目部署 nginx安装包下载 http://nginx.org/en/download.html nginx安装 首先先安装PCRE pcre-devel 和Zlib,因 ...

随机推荐

  1. 8.4考试总结(NOIP模拟30)[毛一琛·毛二琛·毛三琛]

    最有名的莫过于想死一次吗. 前言 至今都不知道题目是个啥... T1 毛一琛 解题思路 \(\mathcal{Meet\;In\;The\;Middle}\) 其实就是一个爆搜... 把整个区间分为两 ...

  2. Redis数据存储和读写

    今天工作群里,有小伙伴问了一个问题,从Redis获取的数据,一会是0,一会是OK. 这引起了我们对Redis数据存储和读写的疑问. 以下是整理的一些技术研究内容. 在 Redis 中,所有的数据存储都 ...

  3. python的一些常用编码技巧(持续更新)

    语法问题 我常用的库函数 1 copy库 import copy copy.deepcopy() 2.list库 from typing import List 获取迭代对象的第一个值 方法一:使用l ...

  4. SpringBoot系列(一)简介。

    概述: Spring Boot 可以简化spring的开发,可以快速创建独立的.产品级的应用程序. 特征: 快速创建独立的 Spring 应用程序 直接嵌入了Tomcat.Jetty或Undertow ...

  5. core dump 路径定义以及监控

    Core Dump 是什么? Core Dump 是指进程异常退出时,操作系统将进程的内存状态保存到文件中,这个文件就是 Core Dump 文件,中文一般翻译为"核心转储",哈, ...

  6. JS 过滤掉两个数组中对象id值相等的项

    const arr1 = [{ id: 1, name: '老二' }]; const arr2 = [{ id: 1, name: '网' }, { id: 2, name: '二位' },{ id ...

  7. AnnotationTransactionAttributeSource is only available on Java 1.5 and higher和windows同时安装jdk7和jdk8

    AnnotationTransactionAttributeSource is only available on Java 1.5 and higher和windows同时安装jdk7和jdk8 出 ...

  8. 认真学习css3-2-css的选择器

    关于有哪些选择器,具体可以查看w3school. 本文写了一个考卷的例子,带有部分js,jquery.不会针对每个选择器做示例,只练习了一些常用的,有意思的. 先看html/js代码: <!DO ...

  9. 【论文阅读】Optimization-Based Collision Avoidance

    前言与参考 论文地址:https://ieeexplore.ieee.org/document/9062306 文章是2018年5月提出的,但是到了2020年才发表到ACC 所以时间轴上写的是2021 ...

  10. nn.Conv2d()中dilation参数的作用

    nn.Conv2d()中dilation参数的作用 下面这张图很好的描述了这个参数的作用 优点: 这样每次进行单次计算时覆盖的面积(感受域)增大,最开始时3*3 = 9 然后是5*5 = 25最后是7 ...