nuxt.js vue deploy applications to the server process

Due to the need seo recently rendered under the project will be used ssr transplant Road nuxt.js

After the migration is complete, smooth all the way, but by the time, was a headache to deploy to the server, but eventually successfully completed.
Now the record about the process of deployment.

Note: When the deployment process, refer to the next: HTTPS: //segmentfault.com/a/11 ...

One: to build nginx + node + npm + pm2 environment

Our nginx version 1.12
the Node version is v8.11.1
npm version 5.6.0
PM2 version is 2.10.2

Specific installation environment, there are online tutorials, not in the narrative directly into the body.

One: Configure nginx proxy listening port 3002, the port package 3002 package

Set in the project in package.json under nuxt.js
image description

Create a host binding in the vhost in nginx

 

upstream nodenuxt {
    server 127.0.0.1:3002; #nuxt项目 监听端口
    keepalive 64;
}

server {
    listen 80;
    server_name mysite.com;
    location / {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;  
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Nginx-Proxy true;
        proxy_cache_bypass $http_upgrade;
        proxy_pass http://nodenuxt; #反向代理
    }
}

Two: After the project is done locally, npm run build packaged applications
after the package is completed, we will

.nuxt
static
nuxt.config.js
package.json

To the server space, you need to upload files as follows
image description

Three: the deployment running on the server

  1. Run npm install the installation package in the dependency
  2. Services run npm start to run up the rendering nuxt

At this point we can enter mysite.com in the browser visited. Server rendering out instantly, but this is not ideal, whether resident background process stability?

Four: pm2 open process Guardian

Into the corresponding application directory, execute the following command

pm2 start npm --name "my-nuxt" -- run start

My-nuxt the name of our project is the name of the package.
After you perform pm2 start command, we look at the process list with pm2 list, I cut my own list of what pm2 server:
image description

Great service completed! !

Guess you like

Origin www.cnblogs.com/plBlog/p/11428131.html