Nginx has the characteristics of reverse proxy (the difference between note and forward proxy) and load balancing.
The Nginx is installed on the 192.168.1.108 Linux machine. Installation Nginx first to install the OpenSSL library,Gcc,pcre,zlib Library and so on .
Tomcat is installed on both the 192.168.1.168 and 192.168.1.178 machines. The client accesses the 192.168.1.108 reverse proxy by accessing the
192.168.1.168 and 192.168.1.178 in the project content of the Tomcat deployment.
1.Linux installation of Nginx (machine 192.168.1.108)
install the OpenSSL library.
Yum install-y OpenSSL openssl-devel
need to install gcc:yum install gcc-c++
Install PCRE yum install-y PCRE pcre-devel
Install zlib library yum install-y zlib zlib-devel
download nginx:wget http://nginx.org/download/nginx-1. - . 0.tar.gz
Put it under the/usr/local/.
Decompression TAR-ZXVF nginx-1.13.0.tar.gz
Go to Catalog run ./configure Generate Makefile
There's more makefile in the catalogue.
Compiling make
Install: Make install
after the completion of The local directory more Nginx
Start Nginx
Enter the sbin directory to execute ./nginx
View Startup results
Window access 192.168.1.108 nginx default port is
close the./nginx-s stop
cannot be accessed at this time after it is closed
./nginx-s Reload can reload the profile after startup is appropriate for the configuration file to be modified at startup
2. Install Tomcatunder Linux (192.168.1.168 and 192.168.1.178 machines)
The installation process is simple and does not tell. Install Tomcat on another two Linux machines (192.168.1.168 and 192.168.1.178), and deploy a project nginxtest a content of 1111 .... One is 22222 .....
At this time to access a different IP address, but also no use nginx configuration in the reverse proxy server.
3. Nginx as a reverse proxy server
main configuration content in the nginx.conf
A. Configure the server group and add the upstream configuration between the http{} nodes .
192.168.1.168:9090 and 192.168.1.178:9191 are another two Linux machines tomcat (see above 2)
Upstream lxstest{
Server 192.168.1.168:9090;
Server 192.168.1.178:9191;
}
B. Modify The port number of the Nginx monitor to 7777 (change any line, do not change).
server {
Listen 7777;
......
}
C. in location{} , use proxy_pass to Configure the reverse proxy address; here "http:/" can not be less, the following address and the first step The names of the upstream definitions remain consistent. (The above is lxstest, so http://lxstest)
Location/{
root HTML;
Index index.html index.htm;
Proxy_pass http://lxstest;
}
After the above modification, start the nginx of the 192.168.1.108 machine
Last visit 192.168.1.108:7777/nginxtest the same address out of different pages, stating that a moment to visit is 192.168.1.168, a while to visit is 192.168.1.178
http://192.168.1.108:7777
equal to = = = =
Equivalent to =====
Finally, we'll find the corresponding tomcat.
Then find the corresponding nginxtest project.
Tomcat cluster under Nginx reverse proxy in Linux