Principle: Nginx reverse proxy principle
Nginx configuration
Nginx is a high-performance HTTP and reverse proxy service. Many large websites use Nginx for HTTP server hosting.
Install the compilation environment gcc g++
Enter the root directory:
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
Install PCRE
Let Nginx have the rewrite function when the PCRE function is enabled, download PCRE
wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
Unzip the installation package
tar zxvf pcre-8.35.tar.gz
Enter the installation package directory:
cd pcre-8.35
Compile:
./configure
Install:
make && make install
Install Nginx
Back to the root directory:
cd /root/
wget http://nginx.org/download/nginx-1.16.0.tar.gz
Unzip the installation package:
tar zxvf nginx-1.16.0.tar.gz
Note: The current decompression address must be selected here. After decompression is completed, it will be the directory where Nginx is located. This example is decompressed under the root root directory.
Go to the installation directory:
cd nginx-1.16.0
Compile:
./configure --with-http_ssl_module
Install:
make && make install
Start and stop Nginx:
Go to the Nginx installation directory:
cd //usr/local/nginx/sbin
Start Nginx:
./nginx
Stop Nginx: (do not stop first)
./nginx -s stop
Configure Nginx configuration file
Go to the Nginx configuration file directory:
//usr/local/nginx/conf
Open the Nginx configuration file:
vim nginx.conf
After modifying the configuration file, go back to the sbin directory and restart Nginx
./nginx -s reload
Install and configure Node.js
Download Node.js (I downloaded it in the root directory)
wget https://nodejs.org/dist/v10.11.0/node-v10.11.0-linux-x64.tar.xz
Unzip, also in the root root directory:
tar xvf node-v10.11.0-linux-x64.tar.xz
Create soft links to make node and npm names globally valid
ln -s /root/node-v10.11.0-linux-x64/bin/node /usr/local/bin/node
ln -s /root/node-v10.11.0-linux-x64/bin/npm /usr/local/bin/npm
ln -s /usr/local/bin/node /bin/node
ln -s /usr/local/bin/npm /bin/npm
Verify that Node.js was successfully installed:
node -v
(When the version number appears, the installation is successful)
Install PM2 to manage Node.js services
PM2 is a Node.js process management tool, which can be used to simplify many tedious tasks of node application management, such as performance monitoring, automatic restart, load balancing, etc.
Main features:
- Built-in load balancing (use node cluster cluster module, but use all CPUs on the server)
- Running in the background (commands like node app.js run directly in the foreground, unstable and easy to break)
- 0 seconds shutdown reload
- Stop erratic processes, avoid infinite loops
- console detection
Install PM2 (global installation):
npm install -g pm2
Create a soft connection to make the pm2 command globally effective:
ln -s /root/node-v10.11.0-linux-x64/bin/pm2 /usr/local/bin/pm2
ln -s /usr/local/bin/pm2 /bin/pm2
Package project, publish server
Package front-end Vue files
npm run build
Copy the file generated by dist to the public directory of the Node project, and then put the Node project on the server, you can choose the FTP tool
Start the Node project
Enter the Node project root directory.
pm2 start app.js --name kanglang-music
Use pm2 list to view the running status of the project
Restart project service
pm2 restart kanglang-music
Reminder: Never forget the firewall
CentOS view port occupancy command, list all ports
netstat -ntlp