This Tutorial environment

Hardware configuration: Aliyun host domain name

System: centos7.4

The software used is:

navicat

xshell5

If you need to buy domain name and server, please refer to the first half of my other article: build nodeJS server from scratch, configure domain name resolution + HTTPS certificate (take Aliyun Linux server as an example).

1. Yum install the necessary modules

yum -y install gcc gcc-c++ autoconf pcre-devel make automake
yum -y install wget httpd-tools vim
Copy the code

2. Configure the yum source and install nginx

sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
Copy the code
sudo yum install -y nginx
Copy the code

3. Start nginx correctly

The /var/run/nginx.pid file is not generated when the nginx service is started for the first time, because the aliyun service occupies port 80 and needs to be restarted.

netstat -anp|grep 80 
Copy the code

View and find the process ID

kill1671-9kill-9 1002 Nginx Restarts the nginx service. Then you can use nginx normally-s quit 
nginx -s reload
nginx -s stop

Copy the code

You can then see the web page print on the terminal

curl localhost 
Copy the code

To open and display content in the browser, you need to configure the security group of Ali Cloud server

Copy the IP directly to the browser to open

For subsequent convenience, set nginx to start at boot

sudo systemctl enable nginx.service
Copy the code

4. Install Node and NPM

First, ensure access to the EPEL depot

sudo yum install epel-release
Copy the code

Install the node

sudo yum install nodejs
Copy the code

After installation

Node -v NPM -v indicates that the installation is successfulCopy the code

5. Install common Node packages

Change the use of Taobao source:

npm config set registry https://registry.npm.taobao.org
Copy the code

Verify the configuration

npm config get registry
Copy the code

Global installation

npm i pm2 webpack vue-cli n yarn -g
Copy the code
node -v # Discover node version 6.x, need to upgrade node, because my project is using nodev8.11.4N v8.11.4Upgrade to 8.11.4
Copy the code

6. Install, upload and download packages

Um -y install LRZSZ Enter sz, a pop-up window is displayed, you can upload the server files to the local PC. Enter rz and press Enter, a popup window will appear, you can upload the local file to the server.Copy the code

7, Install mysql

mkdir down && cd soft

mkdir app backup download logs work && cd download

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm Download the source you need to install
rpm -ivh mysql-community-release-el7-5.noarch.rpm   # Install the download source
yum install mysql-server # mysql installation
service mysqld start Start the mysql serviceMysql -v Check the versionCopy the code

8. Change the mysql password and configure the remote connection

mysqladmin -u root password 'password'Mysql -uroot -proot mysql -uroot -prootCopy the code

Terminal input in the database

GRANT ALL PRIVILEGES ON *.* TO 'root'@The '%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Mysql > alter database name
The second is the name of the database table. * stands for allowing access to any table
#root indicates the user name for remote login, which can be customized
#% indicates that any IP address is allowed to log in. If you want to specify a specific IP address, just replace the %
#password Indicates the password used for remote login, which can be customized


flush privileges;
Let the command take effect. Note that at the end of each command line, add; Otherwise, it will not be implemented
Copy the code

Enter the query command to see the final result.

SELECT DISTINCT CONCAT('User: '' ',user,' 'The '@'' ',host,' ''; ') AS query FROM mysql.user;
Copy the code

Before this, we must first to ali cloud security group inside the increase of security rules, otherwise or remote access, as the previous HTTP: 80 port

Remote login through CMD interface of your own computer

Mysql -h server IP address -p 3306 -u root -p password

Client logins (using Navicat) also use a graphical interface in daily development for easy operation

Here is the download address of this software and the crack patch Navicat

Install Git and pull the repository project

yum install git

git --version # check version

mkdir -p /www/git && cd /www/git

git clone https://github.com/jgchenu/JGBlog-Server.git # Blog backend repository
git clone https://github.com/jgchenu/Blog-Web.git # Blogs manage warehouses
git clone https://github.com/jgchenu/Blog-Admin.git ## Blog repository
# Change the name to make it easier to spell
mv JGBlog-Server server && mv Blog-Web web && mv Blog-Admin admin
Copy the code

Package react and start the Node service

Here is the package.json homepage of the web repository. Change it to the domain address you want to deploy as the root directory

It is recommended to fork the warehouse to your own warehouse first, then pull the warehouse, modify and resubmit to your own warehouse, convenient for subsequent changes.

Pay attention pay attention here to remember!!

Add pm2.json to the project root directory

{
    "apps": {
        "name": "wuwu"// Project name"script": "./bin/www"// Execute the file"cwd": ". /"// Root directory"args": "", // Parameters passed to the script"interpreter": "", // Specifies the script interpreter"interpreter_args": "", // Arguments passed to the interpreter"watch": true// Whether to listen for file changes and then restart"ignore_watch": [// do not listen to the file"node_modules"."logs"]."exec_mode": "fork"// Application startup mode, supporting fork and cluster modes"instances": 1, // Number of application startup instances. The default value is fork only in cluster mode. Or Max"max_memory_restart": "500M", // The maximum memory limit, which is automatically restarted"error_file": "./logs/app-err.log"// Error log file"out_file": "./logs/app-out.log"// Normal log file"merge_logs": true// Set to append logs instead of creating new logs"log_date_format": "YYYY-MM-DD HH:mm:ss"// Specify the time format of the log file"min_uptime": "60s"// An application running less than that time is considered to have started abnormally"max_restarts": 30, // The maximum number of abnormal restarts, that is, the number of restarts during min_uptime;"autorestart": true// The default istrue, automatically restarts when an exception occurs"cron_restart": ""// Crontab restart the application in cluster mode."restart_delay": 10, // Delay the restart time in case of abnormal restart"env": {
           "NODE_ENV": "production", // Environment parameter, currently specified as production environment process.env.node_env"REMOTE_ADDR": "In love with loud."               // process.env.REMOTE_ADDR
        },
        "env_dev": {
            "NODE_ENV": "development"Pm2 start app.js --env_dev"REMOTE_ADDR": ""
        },
        "env_test"Pm2 start app.js --env_test"NODE_ENV": "test"."REMOTE_ADDR": ""}}} copy code nuggets recruitment operations manager, the content of the: Wu Wu links: https://juejin.cn/post/6844903617019772936 source: the nuggets copyright owned by the author. Commercial reprint please contact the author for authorization, non-commercial reprint please indicate the source.Copy the code

Then add it to package.json

 "pm2": "pm2 start pm2.json" 
Copy the code

sudo chmod 777 /www  
Add read/write permission to/WWW directory
cd /www/git/web && yarn
Wait for dependencies to download
yarn build # packaged
cd /www/git/admin && yarn
yarn build # packaged
cd /www/git/server
vim config/index.js # Change the database password to set your own password
yarn  
yarn pm2  # pm2 start service daemon, watch option to monitor node file change will restart the node process mode of the fork, pm2. Through the modification of the above can be json configuration

Copy the code

Use nginx mapping service, and proxy forwarding

cd /etc/nginx/conf.d
touch web.conf
Copy the code

Copy the configuration information below

Add web blog page nginx profile

server {
            listen 80;

            server_name blog.jgchen.xin;

            root /www/git/web/build;

            index index.html;

            location / {
                try_files $uri $uri/ /index.html;
            }

            location /api/ {
                    proxy_pass http://localhost:8000/api/;
           }
            location /upload/{
                    proxy_pass http://localhost:8000/upload/;
            }
           gzip on;
           gzip_buffers 32 4k;
           gzip_comp_level 9;
           gzip_min_length 200;
           gzip_types text/css text/xml application/javascript;
           gzip_vary on;
    }

Copy the code

Add admin blog page nginx profile

touch admin.conf
Copy the code

Copy the configuration information below

server {
            listen 80;

            server_name admin.jgchen.xin;

            root /www/git/admin/build;

            index index.html;

            location / {
                try_files $uri $uri/ /index.html;
            }

            location /api/ {
                    proxy_pass http://localhost:8000/api/;
           }
            location /upload/{
                    proxy_pass http://localhost:8000/upload/;
            }
           gzip on;
           gzip_buffers 32 4k;
           gzip_comp_level 9;
           gzip_min_length 200;
           gzip_types text/css text/xml application/javascript;
           gzip_vary on;
    }
Copy the code
# Restart nginx
nginx -t # prompt successful
nginx -s reload 
Copy the code

11. Aliccloud configures subdomain name resolution

Add admin.jgchenh. xin subdomain name resolution

Open your browser to blog.jgchenh.xin

admin.jgchen.xin

If you need to add HTTPS, please refer to the second half of my other article: Build nodeJS server from zero, configure domain name resolution + HTTPS certificate (take Aliyun Linux server as an example)

Finally, step by step writing is not easy, feel helpful, no reward, put ❤ on the light line, thank you.