The efficiency of nginx processing static pages is significantly higher than Tomcat, so using Nginx to handle the static pages requested by the user, Tomcat handles dynamic pages with Nginx and Tomcat to achieve the effect of static and dynamic separation, thereby improving concurrency.
Implementation environment: Redhat 6.5
Implement host: 172.25.16.2 Nginx
172.25.16.3 Tomcat
172.25.16.4 Tomcat
Software Download:
Download jdk:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
Download tomcat:http://tomcat.apache.org/download-80.cgi
Download nginx:http://nginx.org/en/download.html
On the Server2 host source compiled Nginx
[email protected] nginx-1.6.2]# Yum install-y pcre-devel gcc-c++ openssl-devel zlib-devel cmake//installation according to Raibao
[Email protected] ~]# TAR-ZXVF nginx-1.6.2.tar.gz
[Email protected] ~]# CD nginx-1.6.2
[Email protected] nginx-1.6.2]# vim AUTO/CC/GCC
Cflags= "$CFLAGS-G"//Remove this line of debug-mode compilation comments, compiled after the program only hundreds of K
[Email protected] nginx-1.6.2]#/configure--prefix=/usr/local/nginx/--with-http_stub_status_module--with-http_ Ssl_module
[[email protected] nginx-1.6.2]# make && make install
[[email protected] sbin]# ln-s/usr/local/nginx/sbin//usr/local/bin///Soft connection Nginx startup file
[[email protected] ~]# useradd-d/usr/local/nginx/-m-s/sbin/nologin nginx//Add Nginx user and set home directory
2. Configuring Tomcat and JDK on Server3 and Server4
[Email protected] ~]# TAR-ZXVF jdk-7u79-linux-x64.tar.gz
[Email protected] ~]# MV jdk1.7.0_79//usr/local/jdk/
[Email protected] ~]# Vim/etc/profile
Java_home=/usr/local/jdk
Path= $PATH: $JAVA _home/bin
Classpath=.: $JAVA _home/bin: $JAVA _home/jre/bin
[Email protected] ~]# Source/etc/profile
[[email protected] ~]# java-version//display version, JDK configuration succeeded
Java Version "1.7.0_79"
[Email protected] ~]# TAR-ZXVF apache-tomcat-8.0.24.tar.gz
[Email protected] ~]# MV apache-tomcat-8.0.24//usr/local/tomcat/
[Email protected] ~]# cd/usr/local/tomcat/bin/
[[email protected] bin]#./startup.sh//Open Tomcat
[Email protected] bin]# NETSTAT-ANTLP | grep java
TCP 0 0::: 8080:::* LISTEN 1281/java//8080 http port: Available via Web page Face Direct Access
TCP 0 0:: ffff:127.0.0.1:8005:::* LISTEN 1281/java//8005 shutdown Port: mainly responsible for starting Move off
TCP 0 0::: 8009:::* LISTEN 1281/java//8009 AJP Port: mainly responsible for AJP Scale
Modify Nginx master configuration file
[Email protected] ~]# vim/usr/local/nginx/conf/nginx.conf
User Nginx Nginx;
Worker_processes 2;
PID Logs/nginx.pid;
Events {
Use Epoll;
Worker_connections 1024;
}
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '
' $status $body _bytes_sent ' $http _referer '
' "$http _user_agent" "$http _x_forwarded_for";
Upstream Westos {
Server 172.25.16.3:8080;
Server 172.25.16.4:8080;
}
Sendfile on;
Keepalive_timeout 65;
server {
Listen 80;
Access_log Logs/host.access.log;
Location ~ \.jsp$ {//The dynamic page ending with. JSP is given to the agent Westos processing that is backend tomcat
Proxy_pass Http://westos;
}
Location ~. *\. (html|jpg|txt) $ {//handle static pages by Nginx
Expires 3d;
}
}
}
can now be tested on the client, when the browser accesses the static page Nginx processing, access to the JSP page when the back-end tomcat processing;
This article is from the "8397752" blog, please be sure to keep this source http://8407752.blog.51cto.com/8397752/1685005
Nginx+tomcat realizes static and dynamic separation