The following methods are available in CentOS8 using a hands-on test

Install the node

Method self baiduCopy the code

Copy projects to the server

.nuxt
assets
components
layouts
middleware
pages
plugins
static
store
nuxt.config.js
package.json
package-lock.json
tailwind.config.js
Copy the code

Installation project dependencies

npm install
Copy the code

packaging

npm run build
Copy the code

Install the pm2

NPM install pm2@latest -g // NPM WARN deprecated [email protected]: The Debug versions > = 3.2.0 < 3.2.7 | | > = 4 < this will have a low severity ReDos regression when 2 in a Node. Js environment. It Is it you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797) /usr/local/src/nodejs/bin/pm2 -> /usr/local/src/nodejs/lib/node_modules/pm2/bin/pm2 /usr/local/src/nodejs/bin/pm2-dev ->  /usr/local/src/nodejs/lib/node_modules/pm2/bin/pm2-dev /usr/local/src/nodejs/bin/pm2-docker -> /usr/local/src/nodejs/lib/node_modules/pm2/bin/pm2-docker /usr/local/src/nodejs/bin/pm2-runtime -> /usr/local/src/nodejs/lib/node_modules/pm2/bin/pm2-runtime npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Fsevents @ ~ 2.3.1 (node_modules/pm2 / node_modules/chokidar/node_modules/fsevents) : NPM WARN Notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: Wanted {" OS ":" Darwin ", "arch" : "any"} (current: {" OS ":" Linux ", "arch" : "x64"}) + [email protected]Copy the code

Run the pm2 -h command to query the usage mode

Pm2 -h // Error message -bash: pm2: Command not foundCopy the code

Solution Add a soft link. (If no error message is displayed, ignore it.)

// The first path after -s is found in the message displayed after the installation is successful. The third line/usr/local/SRC/nodejs/lib/node_modules/pm2 / bin/pm2 ln -s/usr/local/SRC/nodejs/lib/node_modules/pm2 / bin/pm2 /usr/local/bin/pm2Copy the code

Nuxt. Config. Js configuration:

Export default {server: {// Configure Nuxt server port: 8080, // default: 3000 host: '0.0.0.0', // default: localhost timing: false },Copy the code

Configure nginx. Conf

Upstream: 0.0.0.0:8080 (nuxt.config.js); } server { listen 8080; # port server_name new-obj.com created on the server; Location / {proxy_pass http://nuxtDemo; # create Nuxt Server name index index.html index.htm; # default open page}}}Copy the code

Launch project:

Pm2 start NPM --name "nuxt" -- run start // NuxT project nameCopy the code

Save the current process state

pm2 save
Copy the code

Generate the startup startup service

systemctl enable pm2-root
Copy the code

Viewing the Status List

pm2 ls
Copy the code
id name mode status cpu memory
0 nuxt fork 0 online 0% 45.8 MB

Pm2 usage

$ npm install pm2 -g              Install pM2 on the cli 
$ pm2 start app.js -i 4           # Background run PM2, start 4 app.jsThe correct number of processes depends on the number of cores in the Cpu$ pm2 start app.js --name my-api  # name process
$ pm2 list                        Display all process status
$ pm2 monit                       # Monitor all processes
$ pm2 logs                        Display all process logs
$ pm2 stop all                    # Stop all processes
$ pm2 restart all                 Restart all processes
$ pm2 reload all                  Stop overloaded processes in 0 seconds (for NETWORKED processes)
$ pm2 stop 0                      Stop the specified process
$ pm2 restart 0                   Restart the specified process
$ pm2 startup                     Create init script to keep the process alive
$ pm2 web                         Run a robust computer API endpoint
$ pm2 delete 0                    Kill the specified process
$ pm2 delete all                  # Kill all processes
Copy the code