An overview of the

Recently in doing a Nextjs project, the final step of the official website tutorial is to deploy Next. Js project, but most of the articles on the Internet are not clear, and most of them are copied, not friendly to the novice, so I have arranged for the server deployment, convenient to have their own deployment needs of friends 👬🏻

Need to prepare

  • Follow this tutorial on the Nextjs website to prepare a simple next-.js APP
  • Install Node Nginx PM2 on the server and configure the environment
  • Run the program to ensure normal access to the server

Installing node on the server

There are no tables here. There are many tutorials online. This article is mainly aimed at deploying Nextjs

Install the PM2

Install PM2 to manage threads

// Install PM2 globally
npm install pm2 -g

// Create the softlink node path
ln -s /root/node-v1014.2.-linux-x64/bin/pm2 /usr/local/bin/

// Check the process
pm2 list

// The thread name is in the start quotes
pm2 start npm --name "nextjs" -- run start

// End the thread
pm2 delete nextjs

Copy the code

Deployment project

Follow this tutorial on the Nextjs website to prepare a simple next-.js APP

Nextjs website

If you open localhost:3000, you can access the page.

Then use FTP software to upload the project to the server /var/ WWW /nextjs/

    // Execute and install the packages
   npm install 
   / / or
   yarn install
Copy the code

Parsing the domain name

Go to the DNS console and point the domain name resolution to the server where the project is deployed

Configure the Nginx configuration file

D in the nginx directory, add the wxlvip.conf file to the conf.d folder. The location of the configuration file may vary depending on the services installed on each server

server {
    listen       80; server_name www.wxlvip.com; Location / {#root Absolute path to the project file root /var/www/nextjs;
       proxy_pass http:/ / 127.0.0.1:3000 /; # Change your host and port
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; }}Copy the code

After the modification is complete, restart the server.

Run the project and access

Go to the /var/www/nextjs/ directory and run the following command to access the domain name

    pm2 start npm --name "nextjs" -- run build
Copy the code

🕯️ : The project is already running. Next, open the bound domain name and access the project normally. Check out my www.wxlvip.com/

If there are any mistakes in this article, please feel free to correct them in the comments section. If this article has helped you, please like 👍 and follow 😊.