1. Introduction

  • Nuxt: A server rendering (SSR) application framework for Vue from Next
  • Pm2: daemon of the Node process, which monitors, automatically restarts, and generates logs
  • Nginx: a lightweight HTTP service framework, reverse proxy server, handling static resources, load balancing, and more

2. Install Nodejs

Creating a file Directory

mkdir -p /usr/local/software
Copy the code

Go to the file directory

cd  /usr/local/software
Copy the code

Download nodeJS (nodeJS version can be changed)

Wget HTTP: / / https://nodejs.org/dist/v8.11.4/node-v8.11.4-linux-x64.tar.gzCopy the code

Decompress the NodeJs file

Tar -zxvf node-v8.11.4-linux-x64.tar.gz -c.. /Copy the code

For nodejs renamed

Mv/usr/local/node - v8.11.4 - Linux - x64 / / usr/local/node8.11.4
#The soft link points to node NPMLn -s/usr/local/node8.11.4 / bin/node/usr/local/bin/node ln -s/usr/local/node8.11.4 / bin/NPM/usr/local/bin/NPMCopy the code

Check whether the soft link is successful

ls -al /usr/local/bin
Copy the code

Soft link Output content

[root@jsyfpre001 bin]# ls -al /usr/local/bin total 3428 drwxr-xr-x 2 root root 4096 Feb 6 14:09 . drwxr-xr-x. 32 root root 4096 Feb 6 14:02 .. 6 14:09 LRWXRWXRWX 29 Feb 1 root root node - > / usr/local/node8.9.1 / bin/node LRWXRWXRWX 1 root root 28 Feb 6 14:09 NPM - > / usr/local/node8.9.1 / bin/NPMCopy the code

Check whether Nodejs is installed successfully

node -v
Copy the code

The successful output is as follows

v8.11.4
Copy the code

3. The pm2 installation

For a tutorial on PM2, see the PM2 Practical Getting Started Guide

npm install pm2 -g
Copy the code

Soft connection pointing

Ln -s/usr/local/node8.11.4 / bin/pm2 / usr/local/bin/pm2Copy the code

If the NPM install speed is too slow, you can change the domestic image source. You are advised to use taobao image source

npm config set registry https://registry.npm.taobao.org
Copy the code

4. Local NUXT project packaging

npm run build
Copy the code

The package will generate a.nuxt folder and upload the following files to the server

.nuxt
static
nuxt.config.js
package.json
Copy the code

The package.json file is shown below

{" name ":" site name ", "version" : "1.0.0", "description" : "site description", "author" : ""," private ": true," scripts ": {" dev" : "> < span style =" max-width: 100%; clear: both; min-height: 1em;Copy the code

You can upload files to the server using the following methods:

  1. SCP -r Local file address root@server IP address: specifies the address for storing the server file
  2. Setting up an FTP Server
  3. Use SVN or Git repository

Install the corresponding dependencies on the server

#Assume that the nuxT package is in a folder named nuxtSSR
cd nuxtSSR
npm install
Copy the code

5.Nginx configures the proxy service

Create a New NuxtServer service
upstream nuxtSSR{
    server 127.0.0.1:3000;
    keepalive 64;
}
server {
    listen 80; Server port 80
    server_name zuxiaoke.com;  This corresponds to the domain name of your server
    access_log /var/log/nginx/nuxtssr_access.log;
    error_log /var/log/nginx/nuxtssr_error.log;
    location / {
        proxy_pass http://nuxtSSR;  This corresponds to the service name created in upstream
        indexindex.html index.htm; }}Copy the code

Restart Nginx

service nginx restart
Copy the code

Pm2 starts nuXT project service and monitors it in real time

pm2 start npm --name "nuxtblog" -- run start --watch
Copy the code
  • Note: Name here corresponds to the project name in package.json
  • View processes: pm2 list
  • Pm2 process management: pm2 show/stop/delete/start ID or process name

Completion of 6.

Matters needing attention:

  1. If permission error occurs, run sudo su – under root
  2. If the Nginx configuration is correct, a 503 time-out problem occurs when the extemet access port 80. However, the pM2 process log does not show an error message. Please delete the project process in PM2, delete all dependencies of the Nuxt project, and reinstall the project

7. The blog

Nuxt server deployment (CentOS7+nginx+pm2)