YiMo.一茉 YiMo.一茉
首页
导航站
  • Java基础知识
  • Java进阶
  • 设计模式
  • Spring
  • SpringMVC
  • SpringBoot
  • SpringCloud
  • Redis
  • MySQL

    • MySQL-基础
    • MySQL-进阶
  • HTML
  • CSS
  • Vue2
  • Vue3
  • uni-app
  • 博客实战教程
  • 图书馆实战教程
  • 网关
  • 数据缓存
  • 搜索
  • 注册中心
  • 消息队列
  • RPC框架
  • Nginx
  • Docker
  • Gitlab
  • Kafka
  • Linux
  • Linux环境搭建

    • 导航
    • 安装JDK
    • 安装MySQL
    • 安装Nginx
    • 安装Tomcat
    • 部署SpringBoot项目
    • 安装node.js
    • 部署Vue项目
    • 安装Redis
  • 每日一更
  • Java基础
  • 前端基础
  • 友链
  • 学习分享
  • 生活
  • 关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

YiMO.一茉

拥抱生活,追寻真实的快乐
首页
导航站
  • Java基础知识
  • Java进阶
  • 设计模式
  • Spring
  • SpringMVC
  • SpringBoot
  • SpringCloud
  • Redis
  • MySQL

    • MySQL-基础
    • MySQL-进阶
  • HTML
  • CSS
  • Vue2
  • Vue3
  • uni-app
  • 博客实战教程
  • 图书馆实战教程
  • 网关
  • 数据缓存
  • 搜索
  • 注册中心
  • 消息队列
  • RPC框架
  • Nginx
  • Docker
  • Gitlab
  • Kafka
  • Linux
  • Linux环境搭建

    • 导航
    • 安装JDK
    • 安装MySQL
    • 安装Nginx
    • 安装Tomcat
    • 部署SpringBoot项目
    • 安装node.js
    • 部署Vue项目
    • 安装Redis
  • 每日一更
  • Java基础
  • 前端基础
  • 友链
  • 学习分享
  • 生活
  • 关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • Nginx

  • Docker

  • Gitlab

  • Kafka

  • Linux

  • Linux环境搭建

    • 导航
    • 安装JDK
    • 安装MySQL
    • 安装Nginx
    • 安装Tomcat
    • 部署SpringBoot项目
    • 安装node.js
    • 部署Vue项目
      • 1、初始工作
      • 2、打包部署vue项目
        • 2.1、打包网站
        • 2.2、上传到服务器
        • 2.3、修改nginx配置
      • 3、配置防火墙
    • 安装Redis
  • 运维
  • Linux环境搭建
YiMO.一茉
2022-11-04
目录

部署Vue项目

# 部署Vue项目

# 1、初始工作

1、先确保vue项目可以在本地正常的运行

2、在linux中新建网站文件夹home

我们放到home文件中

/home/www/dist
1

此时我们需要在服务器上新建www文件夹:

cd /home
mkdir www
1
2
[root@Captian /]# cd home
[root@Captian home]# ll
total 0
[root@Captian home]# mkdir www
[root@Captian home]# ll
total 4
drwxr-xr-x 2 root root 4096 Aug 13 14:04 www
[root@Captian home]# 
1
2
3
4
5
6
7
8

我们没有新建dist文件夹,因为我们待会儿vue项目打包就会生成dist文件夹。

# 2、打包部署vue项目

# 2.1、打包网站

使用vue打包命令,生成dist文件夹:

npm run build
1

如果这个报错的话使用下面的

npm run build:prod
1

你可以在你的项目中看到package.json文件中有设置。

# 2.2、上传到服务器

使用ftp工具将dist文件夹上传至/home/www目录下

# 2.3、修改nginx配置

进入到nginx文件中

[root@Captian nginx]# cd conf
[root@Captian conf]# ll
total 68
-rw-r--r-- 1 root root 1077 Aug 12 17:23 fastcgi.conf
-rw-r--r-- 1 root root 1077 Aug 12 17:23 fastcgi.conf.default
-rw-r--r-- 1 root root 1007 Aug 12 17:23 fastcgi_params
-rw-r--r-- 1 root root 1007 Aug 12 17:23 fastcgi_params.default
-rw-r--r-- 1 root root 2837 Aug 12 17:23 koi-utf
-rw-r--r-- 1 root root 2223 Aug 12 17:23 koi-win
-rw-r--r-- 1 root root 5349 Aug 12 17:23 mime.types
-rw-r--r-- 1 root root 5349 Aug 12 17:23 mime.types.default
-rw-r--r-- 1 root root 2656 Aug 12 17:23 nginx.conf
-rw-r--r-- 1 root root 2656 Aug 12 17:23 nginx.conf.default
-rw-r--r-- 1 root root  636 Aug 12 17:23 scgi_params
-rw-r--r-- 1 root root  636 Aug 12 17:23 scgi_params.default
-rw-r--r-- 1 root root  664 Aug 12 17:23 uwsgi_params
-rw-r--r-- 1 root root  664 Aug 12 17:23 uwsgi_params.default
-rw-r--r-- 1 root root 3610 Aug 12 17:23 win-utf
[root@Captian conf]# vim nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

我们打开nginx.conf文件,修改以下配置

1、修改端口,为了防止和其他的端口有冲突,我们将80端口改为9090端口(自定义)。

2、修改root里dist的路径。

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       9090;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /home/www/dist;   # 路径改成自己的dist路径
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

改完这些之后,我们重启一下nginx

systemctl restart nginx
1

# 3、配置防火墙

由于我们把端口改了,所以现在需要我们把加入的端口加入到防火墙中。

添加端口

firewall-cmd --zone=public --add-port=9090/tcp --permanent
1

然后重启防火墙

systemctl restart firewalld.service
1

我姑且举灰黑的手装作喝干一杯酒

我将在不知道时候的时候独自远行。

​ ——鲁迅

上次更新: 2023/03/05, 20:36:52

← 安装node.js 安装Redis→

最近更新
01
项目实战部署
03-16
02
Maven插件
03-16
03
软件安装
03-16
更多文章>
Theme by Vdoing | Copyright © 2022-2023 YiMO.一茉 | 苏ICP备2022035828 | MIT License | 一茉 All rights reserved.
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×