初始化vue工程,并部署到阿里云nginx

前面已经在阿里云上面装了nginx ,jdk

接下来开始使用springboot  vue mysql 建立工程

初始化vue:

本地环境(win10)安装 node.js  

nodejs.org官网下载 node.js 

在本地解压 或者下一步安装  取决于下载的是msi还是压缩包

完成后 cmd  node -v 显示版本则成功。 

npm自带,npm是node的一个下载依赖包的工具

安装淘宝镜像:

cmd :

npm  install  -g  cnpm  --registry=https://registry.npm.taobao.org

项目初始化

vue 官网:https://cli.vuejs.org/zh/guide/creating-a-project.html#vue-create

安装vue-cli 

cnpm install vue-cli -g   // -g 全局安装ddddd

完成后

初始化 工程

可以使用git的shell 打开当前文件夹

vue init webpack 'project' 

接下来是一些项目信息,可以输入,选择 n  y 等

安装依赖:

cnpm install

运行:

npm run dev

查看:

浏览器:localhost:8080/#/

打包部署到nginx:

运行 :

npm run build 

打包完成后 生成 dist静态文件目录  。

但该 dist下的index.html 直接打开不显示 需要修改如下:


1、查看package.js文件的scripts命令
2、打开webpack.dev.conf.js文件,找到publicPath: config.dev.assetsPublicPath,按Ctrl点击,跳转到index.js文件
3、其中dev是开发环境,build是构建版本,找到build下面的assetsPublicPath: '/',然后修改为assetsPublicPath: './',即“/”前加点。
重新终端运行 npm run build 即可。生成dist 文件夹

将该dist直接放置在nginx的html目录下  ,可以使用winscp 。

配置 config文件

cd /usr/local/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       8080; # 自定端口
        server_name  localhost;

        root  /usr/local/nginx/html/dist;
        index index.html index.html;

        #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;
    #    }
    #}

}

主要修改 server 里面。

重启nginx   ./nginx -s reload

访问阿里云 外网ip +该端口

显示成功。dddd

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值