Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy Node.js project on CVM

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to deploy the Node.js project on the cloud server". In the daily operation, I believe many people have doubts about how to deploy the Node.js project on the cloud server. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to deploy the Node.js project on the cloud server". Next, please follow the editor to study!

Take aliyun as an example, it is recommended to choose CentOS for the server, and configure it according to your own needs. After successful payment, you can go to the console page and reset the root password to log in to the server remotely. You can log in remotely by clicking on the console, or on the host where ssh is installed

# View public network ip# the following is a sample public network ipssh root@150.77.1.85

Environmental installation

Install node.js

# As rootcurl-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# to compile the C++ plug-in yum install gcc-c++ make# or: yum groupinstall 'Development Tools'

Check whether the installation is successful

~ $node-vv12.16.1~$ npm-v6.13.0

Set the Taobao image of Taobao npm

Npm config set registry "https://registry.npm.taobao.org

Global installation of pm2

Npm install pm2-g

Install nginx

Nginx is a lightweight Web server / reverse proxy server and email (IMAP/POP3) proxy server, distributed under the BSD-like protocol. It is characterized by less memory and strong concurrency ability. in fact, the concurrency ability of nginx performs better in the same type of web server. Chinese mainland uses nginx website users: Baidu, JD.com, Sina, NetEase, Tencent, Taobao and so on.

Download nginx

# first confirm to install the following software yum-y install gcc pcre-devel zlib-devel openssl openssl-develcd / usr/localmkdir nginxcd nginx# download the latest version of nginxwget http://nginx.org/download/nginx-1.16.1.tar.gztar-zxvf nginx-1.16.1.tar.gz# and copy it to the nginx folder cp-r / usr/local/nginx/nginx-1.16.1/* / usr/local/nginx/./configuremakemake install

Modify config

Cd confvi nginx.conf# modify configuration file # omit other unmodified 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; # modify here nginx will automatically load all configuration files include / usr/local/nginx/enabled-server/* under enabled-server ...}

Sometimes we need to deploy multiple websites, so we usually create a new configuration file named after the site, such as myblog.conf

Vi default.conf# configuration file upstream nodepro {server 127.0.0.1 keepalive 3000; # the port number that the project runs, modify keepalive 64;} server {listen 80; # Port number to listen server_name xxxx.com www.xxxx.com; # server name, ip address or domain name, you can write more than one, and separate location / {port $remote_addr with a space 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; # to be consistent with the top application name after upstream, you can customize}}

Check whether the nginx configuration is successful

Cd... / nginx-t # modified successfully nginx: the configuration file / www/server/nginx/conf/nginx.conf syntax is oknginx: configuration file / www/server/nginx/conf/nginx.conf test is successful

Start the nginx server

. / nginx

Server domain name filing

Aliyun official website buys domain name and verifies it by real name. After passing the examination, you can start filing.

There is a representative filing system on the official website. Click on the filing area and record according to the prompts (3-15 working days).

In the console, click Network and Security-> Security Group-> configure rules-> add Security Group rules

The protocol type selects the rules to be created, such as mysql (3306), redis (6379), http (80go 80), https (443), which can be customized.

Domain name resolution

Find the list of domain names in the domain name service

Click to analyze

Click add record, the record type is A by default, and the host record can add top-level domain name and second-level domain name. The resolution route is available by default, and the record value is added to the server's public network IP.

At this point, the study on "how to deploy the Node.js project on cloud servers" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report