This is the fifth day of my participation in the First Challenge 2022

Functional description

The blogger found that Serverless does not support socket. IO at present, but he still wants to use this function, so he chose to buy a lightweight server to build his own project. The following is the method to build his own project. The disadvantage is that it is cumbersome, write this process out, so that more developers reduce the difficulty of deployment, let us start to learn ~

Preparations before deployment

  1. A Linux server.
  2. Front-end projects that can run directly locally.

Server side Settings

1. Install the Node environment

Wget https://nodejs.org/dist/v12.18.1/node-v12.18.1-linux-x64.tar.xz tar xf node - v12.18.1 - Linux - x64. Tar. Xz CD Node - v12.18.1 - Linux - x64Copy the code

2. Configure the node

Bak export PATH=$PATH:/root/node-v12.18.1-linux-x64/bin source /etc/profileCopy the code

3. Check whether the Node installation is complete

node -v
Copy the code

4. Installation of forever

npm install forever -g
Copy the code

5. Add tools such as Node, NPM, forever to global variables

ln -s /usr/local/src/nodejs/bin/node /usr/local/bin/node
ln -s /usr/local/src/nodejs/bin/npm /usr/local/bin/npm
Copy the code

Pay attention to the file name in node.js in the path above, according to your actual path.

6. Start front-end projects

forever start app.js
Copy the code

7. Install nginx

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
Copy the code

8. Download and decompress the installation package

CD/usr/local mkdir nginx nginx/CD/download the tar packages wget tar XVF - http://nginx.org/download/nginx-1.13.7.tar.gz Nginx - 1.13.7. Tar. GzCopy the code

9. Run nginx commands

// Go to the nginx directory. CD /usr/local/nginx // Go to the directory. CD nginx-1.13.7 // Run the command installCopy the code

10. Configure nginx. Conf

vi /usr/local/nginx/conf/nginx.conf
Copy the code

11. Start nginx

/usr/local/nginx/sbin/nginx -s reload
Copy the code

Written nginx. Conf

The key to deploying a front-end project to the server is the way nginx.conf is written. As long as this file is written correctly, the deployment is almost complete.

Quick ways to find nginx.conf files:

locate nginx.conf
Copy the code

Nginx. conf

  • CodeSandBox online address

Configuration file description:

server {
    listen 80;
    server_name 124.223.104.214;
}
Copy the code
  • Server_name follows the address of your server
  • Listen 80 refers to the open port on your server. Make sure that the firewall port is enabled on the server Settings.
Proxy_pass http://127.0.0.1:8000; proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; Proxy_buffering off; }Copy the code
  • Location follows the forwarding address
  • Proxy_pass is followed by the back-end address and port deployed on the server that you want to forward to.