When we finished writing node. js project locally, we need to package the file and upload it to the cloud server, so that other people can access and browse the program we wrote through THE URL address. When we applied for and configured ali Cloud ECS server, we also trampled numerous holes. There are many knowledge points covered in this paper, which probably include the following aspects:

  • Apply for aliyun free server
  • Installation node. Js
  • Install the Nginx server
  • Installing the mongoDB Database
  • Install the PM2 process management tool
  • Installing local FTP
  • Launch mobile terminal project

Before also wrote a “Ali cloud server crash self-help guide”, if in the local error to delete some files caused by the server crash, you can refer to my summarized steps to try to recover.

Note: I use MacOS system, if the environment is Windows, some operations in this article will be different.

Apply for aliyun free server

Register an Aliyun account

Choose your login method on the home page, and you can log in through the third-party services of Ali.

Here I use Alipay login, scan code to enter the page and click authorization.

If you don’t have an Aliyun account, you can enter your member name and mobile phone number for quick registration.

After registration, the ECS administrative Console page is displayed

To find new users in the latest activities, we can apply for the aliyun free package for a trial period of one month.

Personal real name authentication

Choose personal version, you need to verify your real name before applying.

Click the personal Real Name Authentication link to enter the real name authentication page and select the personal real name authentication.

Recommend individual pay treasure to accredit attestation, jump to the page hind input home address can complete attestation.

Apply for aliyun free server

Click the “Buy now” button to apply for free cloud server after the certification is completed

Click the free pick button and select Centos/ 7.6 64-bit OS.

Immediately to receive

Then enter the management console page and you can see that a cloud server is running

Resetting the instance password

To find reset instance password in more, click Set Password.

The password is not your Ali Cloud login password, but your cloud server access password, which must consist of uppercase letters, lowercase letters, digits, and special characters.

Restart the instance

After resetting the instance, click in the upper right corner to restart it.

Click ok on the page that pops up

The stopped state is displayed after you restart the instance, which takes about 30 seconds.

Configuring a Security Group

In the sidebar Network and Security, find security groups and click Configuration Rules on the right.

Port range: 1/60000. If this port range is too small to use more services, databases with port 27017 like mongodb will not be installed. The authorization object is 0.0.0.0/0 in order to make it accessible to all ports.

Click OK to save, and you can see our configured security group on the page.

The remote connection

You can use its own remote connection to connect to the server.

Click Remote Connection, the system will provide you with a password for remote connection to your cloud server, this password only appears once, you need to record when it appears.

In the remote connection, the user name is root, and press Enter to enter the previously reset instance access password (the default password is not displayed. After entering the password, press Enter).

However, it is generally not recommended to access the server in remote connection because: If no operation is performed for more than one minute, the connection will be automatically disconnected and you need to re-enter the remote connection password, which is cumbersome. And in its console can not copy and paste instructions, only through the copy command input in the upper right corner of its window to operate, more trouble.

You can access the cloud server through SSH in CMD of the local terminal

Git SSH [email protected](your public IP)Copy the code

You can find the public IP address in the configuration information of the instance

After successful connection, run view file command:

cd /
ls
Copy the code

Installation node. Js

Run the yum command to install Node.js on the cloud server

sudo yum install nodejs
Copy the code

After the installation is complete, run node -v to check the version number:

Installing the Nginx Server (Static server)

The detailed steps are from this article:

Installing Nginx on CentOS 7

www.linuxidc.com/Linux/2016-…

Nginx is a free, open source, high-performance HTTP server and reverse proxy server. It is also an IMAP, POP3, SMTP proxy server. Nginx can be used as an HTTP server for web site publishing and as a reverse proxy for load balancing.

1. GCC installed

GCC GCC is not available, you need to install:

yum install gcc-c++
Copy the code

Installation successful:

2. PCRE PCRE – devel installation

PCRE(Perl Compatible Regular Expressions) is a Perl library that includes the Perl-compatible Regular expression library. The HTTP module of Nginx uses PCRE to parse regular expressions, so you need to install the PCRE library on Linux. Pcre-devel is a secondary development library developed using PCRE. Nginx also needs this library. Command:

yum install -y pcre pcre-devel
Copy the code

Installation successful:

3. Zlib installation

Zlib provides a variety of compression and decompression methods. Nginx uses Zlib to gzip HTTP packages, so you need to install zlib on Centos.

yum install -y zlib zlib-devel
Copy the code

Installation successful:

3. * * * * OpenSSL installation

OpenSSL is a powerful Secure Socket layer cryptographic library that includes major cryptographic algorithms, common key and certificate encapsulation management capabilities, and SSL protocols, and provides rich applications for testing and other purposes. Nginx supports both HTTP and HTTPS, so you need to install the OpenSSL library on Centos.

yum install -y openssl openssl-devel
Copy the code

Installation successful:

Download the nginx installation package

(1) The first method: directly download the.tar.gz installation package, nginx official website address: nginx.org/en/download…

(2) The second way (recommended) : use the wget command to download

Wget -c https://nginx.org/download/nginx-1.10.1.tar.gzCopy the code

I downloaded version 1.10.1, which is the current stable version.

5. Unpack

Still a direct command:

The tar - ZXVF nginx - 1.10.1. Tar. GzcdNginx - 1.10.1Copy the code

Configuration of 6.

In nginx-1.10.1 you don’t need to configure anything, just use the default configuration.

./configure
Copy the code

7. Compile and install

make
make install
Copy the code

Find the installation path:

whereis nginx
Copy the code

8. Start, stop, and restart nginx

cd /usr/local/nginx/sbin/
./nginx 
Copy the code

To query the nginx process:

ps aux|grep nginx
Copy the code

After successful startup, you can see the following page in the browser:

/nginx -s stop: Check the Nginx process ID and then run the kill command to forcibly kill the process. /nginx -s quit: Stop the nginx process after it finishes processing tasks.

Restart the nginx

(1) The first method: Stop and start (recommended) : Restarting nginx is equivalent to stopping and start, that is, running the stop command and then running the start command. As follows:

./nginx -s quit
./nginx
Copy the code

If the nginx configuration file is modified and the configuration takes effect, nginx needs to be restarted. Using -s reload, the configuration takes effect in nginx without stopping nginx first and then starting nginx, as follows:

./nginx -s reload
Copy the code

9. Startup automatically

Add the startup code to rc.local.

vi /etc/rc.local
Copy the code

Enter the letter I – INSERT -, press the up and down keys to control the cursor

Copy and paste the following code

/usr/local/nginx/sbin/nginx
Copy the code

Press ESC to exit and enter the forced save exit command:

:wq!
Copy the code

At this point, nginx is installed and started, stopped, restarted, and booted.

Installing the mongoDB Database

The detailed steps are from this article:

Centos7 Install MongoDB3.4

www.cnblogs.com/web424/p/69…

MongoDB is a product between relational database and non-relational database. Among non-relational databases, it has the most rich functions and is the most like relational database. The data structure it supports is very loose, in jSON-like Bson format, so it can store more complex data types. The biggest feature of Mongo is that the query language it supports is very powerful. Its syntax is somewhat similar to object-oriented query language. It can almost achieve most of the functions similar to single table query of relational database, and it also supports data indexing.

1. Create the yum source file

Vim/etc/yum. Repos. D/mongo - org - 3.4. RepoCopy the code

2. Add the following information

[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

The letter I stands for INSERT write

Copy and paste the above content, press ESC, and type

(colon) wq! (Exclamation mark)Copy the code

Forced save and exit

3. Install the mongo

Installation command:

yum -y install mongodb-org
Copy the code

Display after installation:

4. After the installation, check the installation position of Mongo

whereis mongod
Copy the code

To view the modified configuration file, run the vim /etc/mongod

5. Start the mongo

systemctl start mongod.service
Copy the code

By the way, the command to stop mongodb is systemctl stop mongod.service

6. Check the mongodb status

systemctl status mongod.service
Copy the code

If active (Running) is displayed, it is successfully enabled.

7. Stop the firewall

CentOS 7.0 uses the iptables firewall by default.

Disable the firewall for Internet access.

systemctl stop firewalld.service
Copy the code

8. Do not start the firewall upon startup

systemctl disable firewalld.service
Copy the code

9. Set startup

systemctl enable mongod.service
Copy the code

10. Start Mongo shell to view the database

After performing the preceding steps, run the mongo command to check the database show DBS.

11. Set remote access to mongodb

After setting up, you can connect to the database locally

The input

vim /etc/mongod.conf
Copy the code

Edit the mongod. Conf configuration file, go to bindIP, comment out the line by pressing I and typing #. Type :wq! Save and exit.

12. Restart mongo

systemctl restart mongod.service
Copy the code

Install the PM2 process management tool

PM2 is a node process management tool, which simplifies many node application management tasks, such as performance monitoring, automatic restart, and load balancing.

When we start the Node service in the server, if we start it directly through NPM start or node index. Js, once we exit SSH remote login, or close the terminal locally, the service will stop running, so we need to install the node process management tool Pm2. Starting the process with pm2 start does not cause this problem.

Global installation commands:

npm install -g pm2
Copy the code

After the installation is complete, run the pm2 list command to check the status of all processes

Installing local FTP

FileZilla is a free, open source, cross-platform FTP application for MAC and Windows users. Here we are using SFTP connections and the default port number is 22.

After the connection is successful, directories under root are listed

Launch mobile terminal project

1. Modify the project configuration file

Go to the vue-config. js configuration file for your project and change publicPath: to ‘/ V-douban /’ in module.exports.

The path of the local request data also needs to add/V-douban

2. Pack your files

Execute YARN Build to package the project into the DIST package

3. Connect to the FTP server and modify nginx

Go to the /usr/local/nginx/conf directory and transfer the nginx.config file to the local directory.

Modify the nginx.config file to configure the data interface proxy.

The location/API/db {proxy_pass http://47.96.0.211:9000/db; } the location/data/my {proxy_pass http://118.31.109.254:8088/my; } the location/douban/my {proxy_pass http://47.111.166.60:9000/my; }Copy the code

Upload the new nginx.config file to the server, overwriting the original file.

Connect to the database on the terminal and restart the Nginx server.

./nginx -s reload
Copy the code

Go to the /usr/local/nginx/html directory to create a V-douban folder

Upload all the files in the packaged Dist folder to the server

After completion of transmission, you can visit the online project http://39.96.84.220/v-douban on the web page

Online Browsing effect: