Nextjs deployment (pm2)

  1. Configure package.json
	"scripts": {
    
    
		"build": "next build",
		"start": "next start",
	}
  1. 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/
  1. The server installs pm2 and configures it
	yarn add pm2 -g
	//配置
	ln -s /usr/local/node/bin/pm2 /usr/local/bin/
  1. Upload project files to server
    insert image description here

  2. Packaging on the server side

	yarn run build

insert image description here

  1. 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
    insert image description here
  1. view all applications
	pm2 ls

insert image description here

  1. Restart the application
	pm2 restart servername
  • servername ---- custom as above, the name of the application

insert image description here

  1. delete app
	pm2 delete servername
  • servername ---- custom as above, the name of the application

insert image description here
At this point, nextjs is deployed to the server to complete

Guess you like

Origin blog.csdn.net/qq_45142260/article/details/131247054