First, Nginx+tomcat host implementation
1. Host Planning
Nginx Host
|
172.18.12.20
|
Tomcat Host
|
172.18.12.21
|
2. Install the Tomcat host and deploy a simple test page
# yum Install java-1.7.0-openjdk java-1.7.0-openjdk-devel# vim/etc/profile.d/java.sh
Java_home=/usr
Export Java_home
# . /etc/profile.d/java.sh
3. Install Tomcat
# yum install-y Tomcat tomcat-lib Tomcat-webapps Tomcat-admin-webapps
4: Deploy a test page
# mkdir/var/lib/tomcat/webapps/myapp# mkdir/var/lib/tomcat/webapps/myapp/{classes,lib,web-inf,meta-inf}# mkdir/ var/lib/tomcat/webapps/myapp/index.jsp# vim/var/lib/tomcat/webapps/myapp/index.jsp
<%@ page language= "java"%>
<body>
<table align= "centre" border= "1" >
<tr>
<td>session id</td>
<% Session.setattribute ("magedu.com", "magedu.com"); %>
<td><%= Session.getid ()%></td>
</tr>
<tr>
<td>created on</td>
<td><%= session.getcreationtime ()%></td>
</tr>
</table>
</body>
5. Start Tomcat
# Systemctl Start Tomcat
7.nginx Host Installation Configuration
# yum Install-y nginx# vim/etc/nginx/nginx.conf
Location ~* \. (Jsp|do) {
Proxy_pass http://172.18.12.21:8080;
}
# nginx-t# Nginx
650) this.width=650; "src="/e/u261/themes/default/images/spacer.gif "style=" Background:url ("/e/u261/lang/zh-cn/ Images/localimage.png ") no-repeat center;border:1px solid #ddd;" border= "0" alt= "spacer.gif"/>
Second, Apache+tomcat host implementation
Host planning
Apache Host
|
172.18.12.20
|
Tomcata Host
|
172.18.12.21
|
In order not to let Nginx host affect our experiment, we first uninstall Nginx, then install Apache
#yum Remove nginx# yum install-y httpd
Apache Back-end host has three kinds of implementations we separate to one by one demo, note here we are based on virtual host implementation
2. Note Center Host
# vim/etc/httpd/conf/httpd.conf
#DocumentRoot "/var/www/html"
3. The first method of realization
Use HTTPD to bring the proxy module proxy_http_module based on the HTTP protocol to implement
Writing a httpd configuration file
# vim/etc/httpd/conf.d/http_proxy.conf
<virtualhost *:80>
ServerName dy.magedu.com
Proxyrequests off forward Proxy
Proxyvia on indicates which host agent refers to the backend host's
Proxypreservehost on turn off other redirected host names
<proxy *>
Require all granted authorized agent for all access requests
</Proxy>
proxypass/http://172.18.12.21:8080/
proxypassreverse/http://172.18.12.21:8080/
<location/>
Require all granted
</Location>
</VirtualHost>
Test syntax and overload httpd to make the configuration file effective
#httpd-t#systemctl Reload httpd
The second method uses HTTPd's own module proxy_ajp_module to achieve
The difference between this implementation and the first is that different protocols are used, and we can make use of the previous configuration file just to modify the protocol and port.
# mv/etc/httpd/conf.d/http_proxy.conf/etc/httpd/conf.d/ajp_proxy.conf
<virtualhost *:80>
ServerName dy.magedu.com
Proxyrequests OFF
Proxyvia on
Proxypreservehost on
<proxy *>
Require all granted
</Proxy>
proxypass/ajp://172.18.12.21:8009/
proxypassreverse/ajp://172.18.12.21:8009/
<location/>
Require all granted
</Location>
</VirtualHost>
Third use of third-party module MOD_JK implementation
To prevent the original configuration file from affecting our experiment rename the original configuration file
# Mv/etc/httpd/conf.d/ajp_proxy.conf{,.bak}
1. Compile and install MOD_JK
# yum Groupinstall-y "Development tools" "Server Platform Development" # Yum install httpd-devel# tar-xf tomcat-connector S-1.2.40-src.tar.gz # CD tomcat-connectors-1.2.40-src/native/#./configure--with-apxs=/usr/bin/apxs#make && Make install
2. Provide the MOD_JK configuration file
# vim/etc/httpd/conf.d/mod_jk.conf
LoadModule Jk_module modules/mod_jk.so
Jkworkersfile/etc/httpd/conf.d/workers.properties
Jklogfile Logs/mod_jk.log
Jkloglevel Debug
Jkmount/* Tomcata
Jkmount/jk_status StatA
# vim/etc/httpd/conf.d/workers.properties
Worker.list=tomcata,stata
Worker. tomcata.host=172.18.12.21
Worker. tomcata.port=8009
Worker. Tomcata.type=ajp13
Worker. Stata.type=status
#httpd-T #systemctl restart httpd
This article is from the "11243407" blog, please be sure to keep this source http://11253407.blog.51cto.com/11243407/1787990
Implementation of common Nginx,apache reverse user requests to a Tomcat host