目录
一:部署到服务器上
二:Nginx
三:pm2进程管理
一:部署到服务器上
前提:nuxt是基于nodejs运行的,安装node是第一步,因此确保已经安装 Node.js 
 (1)nuxt项目打包
 详细请移步nuxt官网
 第一步、在本地 npm run build,会在.nuxt文件夹下生成dist文件;
第二步、把本地文件的.nuxt,static,package.json,nuxt.config.js,这四个文件夹放到服务器目录文件下
 比如我在服务器上创建了C:\inetpub\nuxt路径。
第三步、用cmd进入目录文件夹,安装依赖
npm install -production
第四步、运行
npm start
此时运行的是 http://localhost:1818;
目录以及项目文件如下:

目录及文件
此时项目在服务器的本地已经可以访问了,但在外部网络是无法进行访问的。这时Nginx就可以出场了。
 目的是通过域名访问到nuxt服务(此处测试的域名为)
二:Nginx
(1)Nginx安装
 第一步、Nginx 的安装步骤比较简单,安装在windows上推荐使用压缩包的安装方式,下载地址;(选择稳定版本)
第二步、下载完成之后,进行解压可以看到如下文件结构
第三步、双击nginx.exe 就启动了
在页面输入localhost。出现如下界面则表示安装成功。默认监听80端口号
第四步、若你的服务器上80端口被占用,则需要修改端口,操作如下:(我这里是将80修改成81,注意修改的端口需要服务器后台已经开放)
 修改nginx安装目录/conf/nginx.conf中的server配置
#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 nodenuxt {
            server 127.0.0.1:3000; # nuxt 项目监听PC端端口
            keepalive 64;
        }
    server {
        listen       81;
        server_name  ;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
     proxy_pass http://nodenuxt;
        }
        #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;
    #    }
    #}
}(2)Nginx启动
 在nginx根目录下打开cmd命令窗口,启动Nginx
start nginx
其他命令
nginx -s reload //重新载入nginx(当配置信息发生修改时) nginx -s quit //停止ngix nginx -h 查看帮助信息
完成以上配置,当你打开浏览器 输入http://:81即可访问到nuxt服务了。
注意:若是多次修改/conf/nginx.conf文件 后重启nginx ,在windows可能会出现多个nginx 进程服务,需要结束这些进程,然后重启方可解决。
通过上述的操作我们已经实现用域名访问nuxt服务了,但关闭服务器上nuxt运行黑窗口时,服务就断了,我们不能实时盯着他吧,因此就需要PM2进行守护了。
三:pm2进程管理
(1)pm2需要全局安装
npm install -g pm2
(2)pm2启动nuxt项目
 --cd 到项目目录
 --启动
pm2 start /node_modules/nuxt/bin/nuxt.js --name 项目名称 (项目目录的node_modules包)
注意:xxx是项目名称,即package.json中的name
 比如我当前为:
pm2启动nuxt.png
(3)pm2其他命令
pm2 list pm2 show 0 #查看进程详细信息,0为PM2进程id pm2 stop all #停止PM2列表中所有的进程 pm2 stop 0 #停止PM2列表中进程为0的进程 pm2 reload all #重载PM2列表中所有的进程 pm2 reload 0 #重载PM2列表中进程为0的进程 pm2 delete 0 #删除PM2列表中进程为0的进程 pm2 delete all #删除PM2列表中所有的进程
 
 
                     
            
        













 
                    

 
                 
                    