In the actual production, Tomcat server is generally not used alone in the project, the response to static resources Nginx performance is better, in addition, because Nginx is dedicated to reverse proxy server, it is easy to implement the Java request forwarded to the back end to the Tomcat container processing, And itself is used to handle static resources.
Usually the Tomcat front end is Nginx or Apache, the back end is Tomcat, also means that no matter what the front-end is the role of the agent to do the work, but note that if you do a reverse proxy based on Nginx, Forwarding requests to Tomcat is forwarded based on the HTTP protocol, but note that the Tomcat connector has HTTPAJP jk2 Jserv, and if the Nginx-based forwarding only supports HTTP forwarding; If Apache does proxy forwarding, Almost all common protocols are supported, but common connection types are the AJP protocol, because the AJP protocol works in binary mode, and the HTTP protocol works in text mode, so AJP is more efficient than HTTP , so it is very often possible to use Apache to deploy a tomcat front-end Web server.
The following schema deployment Nginx+tomcat implements the direction agent:
The reverse proxy system architecture is planned as follows:
Server role
|
Server IP
|
Nginx
|
ETH0:172.16.100.1/16 eth1:192.168.56.10/24
|
Tomcat1
|
Eth0:192.168.56.11/24 |
Tomcat2 |
Eth0:192.168.56.12/24 |
Statichost (Nginx)
|
Eth0:192.168.56.13/24
|
The configuration process is as follows:
Tomcat Service installation configuration:
(1) Installing the JDK
# rpm -ivh jdk-7u9-linux-x64.rpm --files generated after installation of JDK # cd /usr/java/ ; lltotal 4lrwxrwxrwx 1 root root 16 sep 27 09:09 default -> /usr/java/latestdrwxr-xr-x 10 root root 4096 sep 27 09:09 jdk1.7.0_09lrwxrwxrwx 1 root root 21 sep 27 09:09 latest -> /usr/java/jdk1.7.0_09--Configuring the JDK environment variable # vim /etc/profile.d/java.shexport java_home=/usr/java/jdk1.7.0_09export path= $PATH: $JAVA _ home/bin--perform the # . /etc/profile.d/java.sh--test to make the environment variable effective:# java -versionjava version "1.7.0_45"         --JDK version openjdk runtime environment ( RHEL-2.4.3.3.EL6-X86_64 U45-B15) openjdk 64-bit server vm (build 24.45-b08, Mixed mode)
(2) Install Tomcat
--Unzip the tomcat bag to/usr/local # tar xf apache-tomcat-7.0.67.tar.gz -c /usr/local/# cd /usr/local/# ln -sv apache-tomcat-7.0.67 tomcat--Configuring the Tomcat environment variable # vim /etc/ Profile.d/tomcat.shexport catalina_home=/usr/local/tomcatexport path= $PATH: $CATALINA _home/bin# The. /etc/profile.d/tomcat.sh--test is as follows:# catalina.sh versionusing catalina_base: /usr/local/tomcatusing catalina_home: /usr/local/tomcatusing catalina_tmpdir: /usr/local/tomcat/tempusing jre_home: /usr/java/ Jdk1.7.0_09using classpath: /usr/local/tomcat/bin/bootstrap.jar :/usr/local/tomcat/bin/tomcat-juli.jarserver version: apache tomcat/7.0.67server built: Dec 7 2015 13:07:11 UTCServer number: 7.0.67.0OS name: linuxos version: 2.6.32-431.el6.x86_64architecture: amd64JVM Version: 1.7.0_09-b05JVM Vendor: oracle corporation--provides the SRV startup script for Tomcat # vim /etc/init.d/tomcat#!/bin/sh# tomcat init script for Linux.# # chkconfig: 2345 96 14# Description: the apache tomcat servlet/jsp container.# java_opts= '-Xms64m - Xmx128m ' Java_home=/usr/java/latestcatalina_home=/usr/local/tomcatexport java_home catalina_homecase $1 instart) $CATALINA _home/bin/catalina.sh start;; Stop) $CATALINA _home/bin/catalina.sh stop;; Restart) $CATALINA _home/bin/catalina.sh stop sleep 2 $CATALINA _home /bin/catalina.sh start;; *) echo "usage: ' basename $0 ' {start|stop|restArt} " exit 1 ;; esac# chmod +x /etc/init.d/tomcat# chkconfig --add tomcat# service tomcat start--Check the TOMACAT default listener port as shown below:# ss -tunlp | grep javatcp LISTEN 0 100 :::8080 :::* users: (("Java", 19525,42) tcp listen 0 1 ::ffff:127.0.0.1:8005 :::* users: (("Java", 19525,47) TCP    LISTEN &NBsp; 0 100 :::8009 :::* Users: (("Java", 19525,43))
Configure the Nginx server process as follows:
--Configuration nginx.confhttp { upstream tomcat { --Define a Load Balancer cluster server 192.168.56.11:8080; server 192.168.56.12:8080; } server { listen 80; server_name localhost; location / { root /usr/share/ nginx/html; index index.jsp index.html Index.htm; } location ~* \. (jsp|do) $ { --definition of all dynamic content forwarding to back-end tomcat cluster proxy_pass http://tomcat;&Nbsp; } location ~* \. (Ico|css|jpg|jpeg|gif|png|pdf|doc|rar|exe|zip) $ { --define all static content forwarding to 192.168.56.13 proxy_pass http://192.168.56.13; } }}
The access tests are as follows:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/88/5C/wKioL1fzV_LBAQ6bAADjsMsOeno245.png "title=" Tomcat001.png "alt=" Wkiol1fzv_lbaq6baadjsmsoeno245.png "/>
Above we can see the JSP dynamic content, the static content has been forwarded to the 192.168.56.13 static content host. Next we configure the Statichost host, the following configuration:
--Installation configuration nginx--copy tomcat images to statichost host # SCP [email protected]:/usr/local/tomcat/webapps/root/*/usr/share/nginx/ Html
Test access is as follows:
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/88/5C/wKioL1fzXYejSorTAAJgP5pjQxc666.png "title=" Tomcat002.png "alt=" Wkiol1fzxyejsortaajgp5pjqxc666.png "/>
The above is the NGINX+TOMCAT realization of debt balance reverse proxy and static and dynamic separation content
This article is from the "Opensamlee" blog, make sure to keep this source http://gzsamlee.blog.51cto.com/9976612/1858793
The Nginx+tomcat of high-performance Web services realizes the reverse agent of debt balance and static and dynamic separation