The Linux version is centos7

Installation node. Js

First, install directly using yum

$	yum -y install nodejs
Copy the code

XXX is not the latest version, which can be viewed using node -v.

Upgrade to the latest version

First install n(NodeJS management tool)

$ npm install -g n
Copy the code

After the installation, install the latest version of Node.js

$ n latest
Copy the code

Then use the

$ n
Copy the code

Select the latest version.

Then change the nodeJS version globally

$ vim ~/.bash_profile
Copy the code

And type in it

export N_PREFIX=/usr/local The actual installation position of node
export PATH=$N_PREFIX/bin:$PATH
Copy the code

Save and exit, then refresh with the following command

$ source ~/.bash_profile
Copy the code

Here the upgrade is successful, check the version again.

Install the mongo

Start by writing the YUM library file

$  sudo vi /etc/yum.repos.d/mongodb-org.repo
Copy the code

Write the following text

[mongo - org - 3.4] name = mongo Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/ mongo - org / 3.4 / x86_64 / gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc gpgcheck = 1 enabled = 1Copy the code

Save and exit; Check available libraries:

$  yum repolist
Copy the code

If you see

.. repo id repo name mongodb-org-3.2/7/x86_64 mongodb Repository..Copy the code

You can install it

$  sudo yum install mongodb-org
Copy the code

When the installation is complete, start it

$  sudo systemctl start mongod
Copy the code

Install Nginx

preparation

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

After the installation is complete, execute the command to install Nginx:

$  yum install nginx -y
Copy the code

Reverse proxy Configuration

Enter the nginx folder

$  cd /etc/nginx
Copy the code

Open the configuration file:

$  vim nginx.conf
Copy the code

To ignore the rest, let’s look at the server, delete the excess, and transform the server to look like this:

    server {
        listen       80;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

Copy the code

Then we add our own proxy configuration, similar to the following:

server { listen 80; server_name xxx.com www.xxx.top; Location / {proxy_pass http://127.0.0.1:8080; 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_redirect off; }}Copy the code

Explain:

  • Server_nme is the domain name. You can configure the level-1 or level-2 domain name.
  • Proxy_pass is the IP address, usually using 127.0.0.1. You can also write the public IP address of your cloud server.

Server_name can only be the resolved domain name, and you need to add a rule for port 80 in the cloud server security group.

The SSL configuration

The first step is to apply for a certificate and download it locally. They are usually named like this:

// XXX is the domain name cert-1541562634350_xxx.crt cert-1541562634350_xxx.keyCopy the code

After downloading the file, upload it to the cloud server using FTP or similar tools, create cert in /etc/nginx folder, and move the two files to this folder.

Next, write nginx.conf

server { listen 443 ssl; server_name *.xxx.com; root /usr/share/nginx/html; ssl_certificate /etc/nginx/cert/cert-1541562634350_www.funnyfm.top.crt; ssl_certificate_key /etc/nginx/cert/cert-1541562634350_www.funnyfm.top.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 10m; ssl_ciphers HIGH:! aNULL:! MD5; ssl_prefer_server_ciphers on; Location / {proxy_pass http://127.0.0.1:8080; proxy_set_header X-Real-IP$remote_addr;
                proxy_set_header Host $http_host;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
Copy the code

A few notes:

  • SSL monitors port 443 and needs to be added in security rules.
  • Each SSL server must correspond to an HTTP 80 server

After writing, you need to restart Nginx

$  nginx -s reload
Copy the code

Ok, now you can use xxx.com instead of accessing the IP directly.