zoukankan      html  css  js  c++  java
  • nuxt项目部署

    前提: linux服务器

     一、安装node


    ① 下载

    cd /usr/local/src/
    wget https://nodejs.org/dist/v10.11.0/node-v10.11.0-linux-x64.tar.xz 
    

       

    ② 解压

    方法一:

    tar -zxvf node-v10.11.0-linux-x64.tar.xz   // 如果失败就用下面的方法二
    

      

    备用方法二:

    xz -d node-v10.11.0-linux-x64.tar.xz
    tar -xvf node-v10.11.0-linux-x64.tar
    

      

    ③ 重命名

    mv node-v10.11.0-linux-x64 node       
    

      

    ④ 环境变量

    vim ~/.bash_profile             // 打开文件后键盘输入 i 即可开始编辑
      
    PATH=$PATH:$HOME/bin   // 修改前
    PATH=$PATH:$HOME/bin:/usr/local/src/node/bin   // 修改后(蓝色是添加的,不要忘了连接符)
    
    改完按键盘左上角Esc键并输入 :wq (冒号+w+q,不要掉了冒号)
    最后编译刚刚修改的文件 source ~/.bash_profile
    

      

    ⑤ 测试

    node -v
    npm -v
    

      

     二、 安装pm2


    ① 安装

    npm i -g pm2
    

      

    ② 开机自启动

    pm2 startup
    pm2 save
    

      

    三、 nuxt打包上传


    ① 本地打包

    npm run build
    

      

    ② 上传打包后文件(以服务器目录 /web/nuxt 为例) 工具:xftp

    ③ 运行nuxt项目

    cd /web/nuxt
    pm2 start npm --name "my-nuxt" -- run start    // 初次运行项目用这行代码,引号内是这个进程的名字
    

      

    ④ 管理项目

    pm2 list                   # 查看当前正在运行的进程
    pm2 start all             # 启动所有应用
    pm2 restart all          # 重启所有应用
    pm2 stop all             # 停止所有的应用程序
    pm2 delete all           # 关闭并删除所有应用
    pm2 logs                 # 控制台显示所有日志
    
    pm2 start 0              # 启动 id为 0的指定应用程序
    pm2 restart 0           # 重启 id为 0的指定应用程序
    pm2 stop 0              # 停止 id为 0的指定应用程序
    pm2 delete 0           # 删除 id为 0的指定应用程序
    
    pm2 logs 0                     # 控制台显示编号为0的日志
    pm2 show 0                    # 查看执行编号为0的进程
    pm2 monit jsyfShopNuxt     # 监控名称为jsyfShopNuxt的进程
    

      

     三、nginx 代理配置


    特别提示:关闭蓝灯等翻墙代理软件!!!

    #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;
    
        #负载均衡服务器
     	upstream nuxt{
        	server localhost:3000 weight=5 max_fails=2 fail_timeout=600s;  // 特别注意,这里是本机localhost,不能写服务器公网ip
        }
    	
    	
            
        server {
            listen       80;
            server_name  www.lzzj.online;                  // 网站域名
    
            #charset koi8-r;
            access_log  logs/host.access.log  main;
    	 
            #location =/ {
    		  #	 root /web/nuxt;  
    		  #	 return 302 /index.html;
    		  #	 #index index.html;
            #}
    
           location / {
                proxy_pass http://nuxt;                      // 代理到nuxt服务器
            }
        }
       # server {
       #     listen 443;
       #     server_name localhost;
       #     ssl on;
       #     root html;
       #     index index.html index.htm;
       #     ssl_certificate   cert/1539823761775.pem;
       #     ssl_certificate_key  cert/1539823761775.key;
       #     ssl_session_timeout 5m;
       #     ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
       #     ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
       #     ssl_prefer_server_ciphers on;
       #     location / {
       #         root html;
       #         index index.html index.htm;
       #     }
       #  }	
    
    }
    

      

     四、总结


    大概就这些东西了,经过自己的博客、公司的项目,算是第二次配置,今天蓝灯忘了关,导致代理出错,浪费好久才找到原因

  • 相关阅读:
    拖拽组件
    css3动画 巧用label
    轮播图
    弹出框组件,可拖拽
    基于angularJS的分页功能
    身份证验证大全-javascript
    公用拖拽功能插件
    记录那些年我踩过的坑
    节流函数
    手机号码的正则表达式
  • 原文地址:https://www.cnblogs.com/hcxy/p/10042485.html
Copyright © 2011-2022 走看看