background

He wanted to learn something outside of work. He had taught himself a little about Vuejs, nodeJS and Linux, so he decided to develop, deploy and publish a small application. (Purely record the process of their own blind, wrong place also please criticize, thank you very much)


centos7.6

First make a Linux server, a how did not get a server rookie, the simplest of course is to go to Ali cloud to buy a cloud server, but also one key installation system is convenient and fast (here is not to Ali cloud advertising you like also can use Tencent cloud…… Hahaha). If you are a student that is even better, student discount is cheaper, novice use is completely satisfied.


Nginx server

Nginx(” Engine X “) is a high-performance Web and reverse proxy server developed by Igor Sysoev, a Russian programmer. It is also an IMAP/POP3/SMTP proxy server.

Nginx is a good alternative to Apache server in the case of high connection concurrency.


Nginx installation method

1. Install through yum

(1) Add source

By default Centos7 does not have an nginx source. Therefore, run the following command to add the source:

# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpmCopy the code

Install nginx

Yum Search nginx: yum search nginx: yum Search nginx

# yum install -y nginx
Copy the code

Check the nginx version. If the version is displayed, the installation is successful

# nginx -vNginx version: nginx / 1.12.2Copy the code

(3) Start Nginx and set automatic startup

# systemctl start nginx.service
# systemctl enable nginx.serviceCopy the code

(4) Check the nginx file location

# whereis nginxCopy the code

Here is the default path for Nginx:

Nginx configuration path: /etc/ Nginx/PID directory: /var/run/ Nginx. PID Directory: /var/run/ Nginx. The/var/log/nginx/access. The log (5) the default site directory: / usr/share/nginx/HTML

Enter your domain name or IP address to access the address bar



2. Compile and install by downloading

If you have the time, you can try it. I also tried, but the version of the compiled dependency package is too low to compile, so I need to reinstall or update the compiled dependency package. In order to save time, I chose the YUM installation method. Here put a rookie tutorial compiler installation link, there is a need to see


Configuration file nginx.conf



I’m mainly talking about data in the server

Listen, 80; // Open port of the server

server_name xxx.xx.xx.xx; // Your public IP address, or domain name

Root XXXXXX. // Project path

Key reverse proxy

 location / {
		 proxy_set_header X-Real-IP $remote_addr;
		 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		 proxy_set_header Host $http_host;
		 proxy_set_header X-Nginx-Proxy true;
		 proxy_set_header Connection "";
		 proxy_pass http://xxx.xxx.xxx.xxx:3000;
        }
Copy the code

Proxy_set_header Sets the header information

Proxy_pass sets the request address of the reverse proxy (I started nodeJS on this server, so it is the private IP of the server), 3000 is the port that the small server listens on

After setting this, nginx -t checks to see if it is correct



After the check is correct, restart nginx

# nginx -s reload
Copy the code


NVM (Nodejs Version Manager)

There are two ways to build a Node.js environment quickly:

  • Install the official image directly and manually modify environment variables.
  • If you need to switch node.js versions at any time, you can use NVM for version control.

Centos is used as an example to explain how to install Node.js using NVM.

NVM stands for Node Version Manager, which is the Nodejs Version Manager. It allows us to easily switch between versions of Nodejs. The official version of NVM only supports Linux and Mac. Windows users can use nVM-Windows.

The installation

1. First, download and install NVM.

# curl - o - https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bashor# wget - qO - https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
Copy the code

2. Add it to the system after downloading

# source ~/.bashrc
Copy the code

3. The next step is to view the required node version, which is available

# nvm list-romote
Copy the code



4. Next, install the required Node version

# NVM install v10.16.0
Copy the code

Check the versions of Node and NPM




Pm2 (Process Manager 2)

Is the production runtime and process manager for Node.js applications with built-in load balancers. It allows you to keep your applications active forever, reload them without downtime, and facilitate common Devops tasks.

The installation

npm install pm2 -g
Copy the code

Power on and off

Js -i4// Start four server.js processes pm2 restart server.js// Restart the server.js process pm2 stop Pm2 stop server.js// Stop the server.js process pm2 stop0// Stop process 0 pm2 detele all// Delete all processesCopy the code

Viewing the Current Process

Pm2 list// View the running processes. Pm2 show0// View the process whose execution number is 0Copy the code


Nginx, NVM, and PM2 are all installed, leaving node and Vue to develop