This article describes how to install node and nginx for the Ubuntu Server 12.04 LTS 64-bit host on Tencent Cloud, and simply configure the reverse proxy.
The author in the entire installation process encountered a lot of trouble (not to repeat), if you want to pit less, you can follow the steps of this article to install the deployment.
A. New Nodejs installation
Using NVM (Node version manager) is highly recommended, and the installation of other methods is more or less problematic.
The specific steps are as follows:
1. Download nvm via git command
Execute the instructions below, we download the NVM to the/root/git/(remember to install git first):
[root@vm-22-180-ubuntu~] #pwd
/root
[root@vm-22-180-ubuntu~] #mkdir git
[root@vm-22-180-ubuntu~] #cd Git
[root@vm-22-180-ubuntu~] #git clone https://github.com/creationix/nvm.git
2. Configure Environment variables
Here is to modify the. bashrc file, and if it is not clear where it is, you can go back to the root directory execution
#find. -name "*.BASHRC"-print
To search for and get results:
Then use VIM to modify the./etc/skel/.bashrc file (although I personally have made the same changes in the top three files), add the following two lines to the beginning of the file:
Export Nvm_nodejs_org_mirror=https://npm.taobao.org/mirrors/node
Source ~/git/nvm/nvm.sh
The first line is to modify the NVM mirror path to Ali, and the second line is to add NVM to the system environment.
Execute instructions for configuration to take effect after saving:
3. Install Nodejs directly with NVM
Execute instructions
You can install a new version of Nodejs, after the successful installation, the latest version of node is installed on the server:
two. Install Nginx
Here and node is not recommended to use the Apt-get/aptitude form of installation, recommended to go to compile the source code installation.
1. Dependent installation and download
Ensure that gcc-c++ and Libpcre3-dev are installed:
#aptitude Install gcc-c++ Libpcre3-dev
Then I navigate to/home/ubuntu to download some dependent packages and unzip them to the folder:
#wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
#wget http:// prdownloads.sourceforge.net/libpng/zlib-1.2.8.tar.gz
#wget https://www.openssl.org/source/ openssl-1.1.0c.tar.gz
#tar-xzvf pcre-8.36.tar.gz
#tar-xzvf zlib-1.2.8.tar.gz
#tar-XZVF Openssl-1.1.0c.tar.gz
Here we download the Nginx module depends on the PCRE/ZLIB/OPENSSL, the download address of the package is found in their corresponding official website.
The point to note is that pcre do not download the use of Pcre2, otherwise it will cause the Nginx compile process error:
It is recommended to use the pcre-8.36 version provided by the upper code snippet.
Note that if the speed of downloading in the terminal is too slow, the recommended use of the Thunderbolt download in the local, and then through the FileZilla to the file synchronization to the cloud host, the Hundred test bad ~
2. Download and decompression Nginx
First to Nginx official website to find the latest source package download path (as of this time, stable version is http://nginx.org/download/nginx-1.10.2.tar.gz), and then download down (I personally download to the/root path):
[root@vm-22-180-ubuntu~] #cd
[root@vm-22-180-ubuntu~] #pwd
/root
[root@vm-22-180-ubuntu~] #wget http ://nginx.org/download/nginx-1.10.2.tar.gz
Then unzip this zip pack and go into the folder/nginx-1.10.2:
[root@vm-22-180-ubuntu~] #tar-xzvf nginx-1.10.2.tar.gz
[root@vm-22-180-ubuntu~] #cd nginx-1.10.2
3. Compile and install
Execute the following three directives in order:
#./configure--prefix=/home/ubuntu/nginx--with-pcre=/home/ubuntu/pcre-8.36--with-zlib=/home/ubuntu/zlib-1.2.8-- with-openssl=/home/ubuntu/openssl-1.1.0c
#make
#make Install
They work by generating C source files and makefile files, generating binaries, and installing nginx into the specified directory (/home/ubuntu/nginx).
Note that the parameters after the/configure directive specify the installation directory of the Nginx and the dependent module address, respectively.
Since then, Nginx has been installed.
Three. Start Nginx
Perform
#/home/ubuntu/nginx/sbin/nginx
The Nginx service can be started directly at any place:
Can be downloaded to a copy of index.html:
At this time we directly access the cloud host public network IP address, you can see the default page directly:
Look out! If you are unable to access the page through public IP at this point, make sure that the security group in which the cloud hosts are allowed to access all ports.
four. Execute a node service and implement reverse proxy via Nginx configuration
Here we simply implement a node page that listens for Port 3000.
We're going to write a index.js file locally to make a play:
Const HTTP = require (' http ');
Const SERVER = Http.createserver ((req, res) => {
Res.statuscode =;
Res.setheader (' Content-type ', ' text/plain ');
Res.end (' Hello world\n ');
};
Server.listen (3000, () => {
Console.log (' node server is now running/');
};
To execute node index, access to Http://localhost:3000/will have the output of "Hello World":
Then we'll put this file on the cloud mainframe.
Since I have been hooked up to GitHub, readers can download the file directly by following the instructions:
#git Clone Https://github.com/VaJoy/node-test.git
P.S. I personally downloaded to the "/root/node-project/" folder, to execute node instructions are:
#node/root/node-project/node-test/cp1/index
OK, let's go ahead and modify the Nginx configuration. If you forget where the Nginx configuration is, you can perform this instruction to determine:
#/home/ubuntu/nginx/sbin/nginx-t
The nginx of this article is installed under/home/ubuntu, so its configuration file path is "/home/ubuntu/nginx/conf/nginx.conf", and we edit it (plus the code in the Red Box section):
This means that when a request path is "/hello", Nginx requests the proxy to the server's 3000 port (that is, the port on which node listens).
Five. Restart Nginx and Node
Don't forget two o '--1 at this point. We have not restarted the Nginx service after modifying the Nginx configuration; 2. We haven't run the node service on the cloud host (just run it on the local computer).
So we execute the following instructions separately (reboot nginx+ run node):
#/home/ubuntu/nginx/sbin/nginx-s Reload
#node/root/node-project/node-test/cp1/index
At this time direct access to http://public network Ip/hello, you can directly see node running up the page content:
This article to the use of Tencent Cloud front-end children's shoes, the above is the entire content of this article, I hope that the study of everyone to help, but also hope that we support the cloud-dwelling community.