- Configure package.json
"scripts": {
"build": "next build",
"start": "next start",
}
-
The server installs node and configures
The installation steps are omitted
...
configuration (/usr/local/node is the installation directory of node)
ln -s /usr/local/node/bin/npm /usr/local/bin/
ln -s /usr/local/node/bin/npx /usr/local/bin/
ln -s /usr/local/node/bin/node /usr/local/bin/
- The server installs pm2 and configures it
yarn add pm2 -g
//配置
ln -s /usr/local/node/bin/pm2 /usr/local/bin/
-
Upload project files to server
-
Packaging on the server side
yarn run build
- pm2 run application
pm2 start --name servername yarn -- start
- servername ---- customizable, application name
- yarn ----- If you use npm, use npm If you use yarn, use yarn
- view all applications
pm2 ls
- Restart the application
pm2 restart servername
- servername ---- custom as above, the name of the application
- delete app
pm2 delete servername
- servername ---- custom as above, the name of the application
At this point, nextjs is deployed to the server to complete