Cloud Server Purchase

In the aliyun example, you are advised to select CentOS for the server. Select CentOS based on your requirements. After the payment is successful, access the console page and reset the root password to remotely log in to the server. You can click on the console to log in remotely or log in to the host that has SSH installed

Check the public IP address
# The following is an example public IP addressSSH [email protected]Copy the code

Environmental installation

  • Installation node. Js
# As root
curl -sL https://rpm.nodesource.com/setup_12.x | bash -

# No root privileges 
curl -sL https://rpm.nodesource.com/setup_12.x | sudo bash -

yum install -y nodejs

Compile c++ plugins if needed
yum install gcc-c++ make
# or: yum groupinstall 'Development Tools'
Copy the code
  • Check whether the installation is successful
~$node -v v12.16.1 ~$NPM -v 6.13.0Copy the code
  • Set taobao NPM taobao mirror
npm config set registry "https://registry.npm.taobao.org
Copy the code
  • Install pM2 globally
npm install pm2 -g
Copy the code
  • Install nginx

Nginx is a lightweight Web/reverse proxy server and E-mail (IMAP/POP3) proxy server distributed under the BSD-like protocol. In fact, nginx’s concurrent ability is better in the same type of web server. In Mainland China, nginx website users include: Baidu, JINGdong, Sina, netease, Tencent, Taobao, etc.

  1. Download nginx
First you need to confirm the installation of the following software
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel

cd /usr/local
mkdir nginx
cd nginx
Download the latest version of NginxWget http://nginx.org/download/nginx-1.16.1.tar.gz tar - ZXVF nginx - 1.16.1. Tar. Gz# copy to nginx folder
cp -r /usr/local/ nginx/nginx - 1.16.1 / * / usr /local/nginx/
./configure
make
make install
Copy the code
  • Modify the config
cd conf
vi nginx.conf

Modify the configuration file
# omit the other configuration

http {
    server_tokens off;
    include       mime.types;
    default_type  application/octet-stream;
    #access_log logs/access.log main;
    sendfile        on;
    #tcp_nopush on;

    #keepalive_timeout 0;
    keepalive_timeout  65;

    gzip  on;
    
    Nginx will automatically load all configuration files under enabled-server
    include /usr/local/nginx/enabled-server/*; . }Copy the code

Sometimes we need to deploy more than one site, so we usually create a configuration file named after the site, such as myblog.conf

vi default.conf
# config fileUpstream nodePro {server 127.0.0.1:3000;# project run port number, as the actual change
    keepalive 64;
}

server {
    listen 80; The port number to listen on
    server_name xxxx.com www.xxxx.com; The server name, IP address, or domain name can be multiple, separated by Spaces

    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://nodepro; Upstream (" upstream ")}}Copy the code
  • Check whether the nginx configuration is successful
cd. ./nginx -t# change succeeded
nginx: the configuration file /www/server/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /www/server/nginx/conf/nginx.conf test is successful
Copy the code
  • Start the nginx server
./nginx
Copy the code

Server domain name Record

  1. Aliyun official website to purchase the domain name and real name authentication, after passing the audit can start to record
  2. There is a representative filing system on the official website. Click the filing area and file according to the prompts (3-15 working days).
  3. On the console, choose Network and Security > Security Groups > Configuration Rules > Add Security Group Rules
  4. Protocol Type Select the rule to be created, such as mysql (3306), Redis (6379), HTTP (80/80), HTTPS (443), you can customize

Domain name resolution

  1. Find the list of domain names in domain name Services
  2. Click on the resolution
  3. Click Add Record. The default record type is A. Top-level domain name and second-level domain name can be added to host records. Add the public IP address of the server.

The last

Run your Nodejs project on the server

pm2 start app.js
Copy the code

At this point, the extranet can access the site through the domain name. This article is learning record, if there are mistakes, welcome to correct!