Nginx reverse proxy tomcat cluster in Linux, nginxtomcat
Nginx has the characteristics of reverse proxy (difference between attention and forward proxy) and load balancing.
Nginx is installed on the linux host 192.168.1.108 this time. To install Nginx, you must first install the openssl library, gcc, PCRE, and zlib libraries.
Tomcat is installed on 192.168.1.168 and 192.168.1.178. The client accesses
Content of the Project deployed by Tomcat in 192.168.1.168 and 192.168.1.178.
1. Install Nginx in Linux (machine 192.168.1.108)
Install the openssl library.
Yum install-y openssl-devel
Install gcc:Yum install gcc-c ++
Install PCREYum install-y pcre-devel
Install zlib libraryYum install-y zlib-devel
Download nginx: wget http://nginx.org/download/nginx-1.13.0.tar.gz
Mounted under/usr/local/
Unzip tar-zxvf nginx-1.13.0.tar.gz
Run./configure in the directory to generate makefile
Makefile is added to the directory.
Compile make
Install: make install
After completion, nginx is added to the local directory.
Start nginx
Go to the sbin directory and run./nginx
View the startup result
Window access 192.168.1.108 nginx default port 80
Disable./nginx-s stop
When it is disabled, it cannot be accessed.
./Nginx-s reload can reload the configuration file after startup. This is suitable for modifying the configuration file during startup.
2.LinuxInstall Tomcat (192.168.1.168 and 192.168.1.178)
The installation process is simple. Install Tomcat on the other two Linux machines (192.168.1.168 and 192.168.1.178), and deploy a project named nginxTest. The content of the project is 1111 ....... one is 22222 .......
In this case, different IP addresses are accessed, and Nginx configuration is not used as the reverse proxy server.
3. Use Nginx as a reverse proxy server
Mainly configure content in nginx. conf
A. Configure the server group and add the upstream Configuration between http {} nodes.
192.168.1.168: 9090 and 192.168.1.178: 9191 are Tomcat of the other two Linux machines (see the above 2)
Upstream lxstest {
Server 192.168.1.168: 9090;
Server 192.168.1.178: 9191;
}
B. Modify the port number of the nginx listener to 80 and set it to 7777. (You can change the port number as needed ).
Server {
Listen 7777;
......
}
C. In location {}, use proxy_pass to configure the reverse proxy address. Here, "http: //" cannot be small, and the following address must be consistent with the name defined in upstream in step 1. (The above is lxstest, so http: // lxstest)
Location /{
Root html;
Index index.html index.htm;
Proxy_pass http: // lxstest;
}
After the preceding modification, startNginx on 192.168.1.108
Last access192.168.1.108: 7777/nginxTest different pages are displayed at the same address, indicating that 192.168.1.168 and192.168.1.178
Http: // 192.168.1.108: 7777
Equivalent to ====
Equivalent to ======
The corresponding Tomcat
Find the correspondingNginxTest project.