Build a server from scratch

First of all, prepare an Aliyun/Tencent cloud server, using Linux system

Node, the core of everything

Install the NVM before installing node

The curl - o - https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bashCopy the code

or

Wget - qO - https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bashCopy the code

Check whether the NVM version is successfully installed (the terminal may need to be restarted)

nvm --version
Copy the code

Then use NVM to install node

nvm install node
Copy the code

During node installation, an error may occur if the GCC version is too early. As a result, the node cannot be installed. Upgrade GCC

Upgrade/install GCC

GCC download address ftp.gnu.org/gnu/gcc/, can…

CD /usr/local// / Go to local under the root directoryCopy the code

Select the GCC version to download and decompress

Wget tar ZXVF GCC - http://ftp.gnu.org/gnu/gcc/gcc-7.1.0/gcc-7.1.0.tar.gz - 7.1.0. Tar. GzCopy the code

Go to GCC

CD GCC - 7.1.0 /. / contrib/download_prerequisitesCopy the code

GCC source compiler to install the dependency package

yum install m4 -y

yum install gmp-devel.x86_64 -y

yum install mpfr-devel.x86_64 -y

yum install gcc-c++.x86_64 -y
Copy the code

Go back to the local directory and create a build folder

The mkdir GCC - build - 7.1.0 CD GCC - build - 7.1.0Copy the code

Execute orders in turn

/usr/local/gcc-7.1.0/configure --enable-checking=release --enable-languages=c, C ++ --disable-multilib make // installCopy the code

Then view the version to confirm that the installation is successful

GCC - v 7.1.0Copy the code

Then you can install node

NVM install 14.17.3Copy the code

Deploy the project to the server

Installing Git on the server

yum install -y git

or

yum install git-all
Copy the code

Configure the SSH key for the server, then copy the contents of the generated.ssh/id_rsa.pub to the code cloud /GitHub/GitLab to add SSH

Ssh-keygen -t rsa -c "[email protected]" // Press EnterCopy the code

Clone the project to the server

Git clone SSH addressCopy the code

Packaging project

CD vue-demo NPM I // Installation depends on NPM run build // packageCopy the code

Install nginx and configuration

yum -y install nginx
Copy the code

Go to the nginx/confi.d directory in etc and create a configuration file named.conf

Need to use PM2 management

server { listen 80; server_name txclass-api.yutouweb.cn; / / domain access_log/WWW/log/jsppapi/access. The log. / / log error_log/WWW/log/jsppapi/error. The log. location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forward-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Nginx-Proxy true; Proxy_pass http://127.0.0.1:3002; // Reverse proxy proxy_redirect off; }}Copy the code

Packaged directly, such as the Vue React project

server { listen 80; server_name xiaoqiu.yutouweb.cn; access_log /www/log/vue-demo/access.log; error_log /www/log/vue-demo/error.log; location / { root /www/vue-demo/dist; index index.html; }}Copy the code

Create configuration files

Create a WWW folder in the root directory CD/mkdir WWW // create a log folder CD WWW mkdir log // Create a project folder CD log mkdir vue-demo // Create a project log file CD vue-demo touch access.log error.logCopy the code

After modifying the configuration

Nginx -t // Verify the configuration systemctl restart nginx restarts the nginxCopy the code

Ali cloud configuration domain name and open security group port

Configuration of the domain name

After purchasing the domain name, go to Aliyun-DNS resolution-Add Record to add A record of A, the host record is the tertiary domain name, which is consistent with the server_name in the nginx configuration file. The record value is the public IP address of the server instance, for example: A record xxx.xxx.cn 47.xxx.xxx.xxxCopy the code

Configuring a Security Group

Under cloud server ECS-Network and Security-Security Group, create security group access rules: Inbound/outbound: Open port 80/443 and configure the security group on the required serverCopy the code