springBoot+vue(前台用户页面+后台管理页面)部署到腾讯云服务器(上)

**前提条件:**首先购买服务器之后,安装jdk、tomcat(如果是war包要安装)、MySQL、nginx
**说明:**我是在一个nginx上部署了两个vue前后台页面(以后简称项目),也就是说公用一个端口访问,只是其中一个比另一个多了个访问目录,例:
http://服务器ip

http://服务器ip/musicmanage
之所以没加端口号是因为nginx中使用的是80端口,默认的所以不用加。
**另:**下面先讲的是部署出错的情况,之后是改正的情况,此处的出错指的是当部署两个vue项目之后,一个在浏览器中可以访问另一个是空白页的情况

部署两个vue写的前后台页面

1.将两个vue页面打包

使用npm run build 命令将两个vue项目打包,这样你会发现新生成了一个dist文件夹。
在这里插入图片描述
在这里插入图片描述

2.连接到服务器并上传上面的dist文件夹中的内容

这里使用的是Xshell连接到服务器
这里使用的是Xshell连接到服务器之后
在这里插入图片描述
之后在这里插入图片描述
这里使用的是Xftp来作为上传工具,之后在左侧自己的电脑中找到第一步中的dist文件夹中的内容,选中拖拽到右侧你的自己创建的目录中去,两个vue项目都是如此操作,之后就到了nginx部署了,如下
在这里插入图片描述
查看你的nginx位置,之后进入,如下:
在这里插入图片描述
你会发现conf和sbin目录,之后进入conf目录,如下:
在这里插入图片描述
之后编辑nginx.conf,使用vim nginx.conf命令如下:
在这里插入图片描述
之后你会看到一堆配置,如下:

#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       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            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;
    #    }
    }
}

在这原始配置(未改动)中,我们要注意以下部分(要进行配置的地方)

#user  nobody;    **最开始那行**

 server {
        listen       80;  //要监测的端口
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {    //配置的要访问vue的页面
            root   html;
            index  index.html index.htm;
        }

首先,修改上面的location 位置,如下:
在这里插入图片描述

此处的root 后的路径为我的之前上传的dist文件内容的所在位置,这里你要用自己的。之后:
在这里插入图片描述

这里是我的第二个vue的dist的位置(http://服务器ip/musicmanage),这里要用alias而不是root,在这个location之后的“/musicmanage”你可以随便起,但要注意下面的$uri/之后的“/musicmanage/index.html”要保持一致。
**最后如果你的dist中的内容的保存位置是root或者别的拥有者的目录的话你要将#user nobody;改为user root此处的root可以是别的拥有者,例如我的:
在这里插入图片描述
**
这样就部署完成

3.启动nginx

如果你之前没启动过nginx那么你可以直接启动:

cd usr/local/nginx/sbin
./nginx

如果你的nginx正在启动着,因为更改了配置文件所以需要重启:

cd /usr/local/nginx/sbin
./nginx -s reload

4.发现空白页

这样你就可以访问了,你会发现,你配置的根路径的vue姓项目可以访问,也就是下面的这个在这里插入图片描述
另一个访问就是空白页面

5.改正空白页的情况

第一个项目像之前一样直接build不用动,在vscode中打开第二个项目(http://服务器ip/musicmanage)之后如下:

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

之后从新build上传,重复第2,3部之后再次访问你就会发现两个页面都可以访问了,至此vue部署部分就结束了,后台spring Boot部分就下次说咯

关于下次spring boot部分部署的事,下次就知道了

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值