Nginx+tomcat is currently the mainstream Java Web architecture, how to let nginx+tomcat work at the same time, can also say how to use Nginx reverse proxy tomcat back-end equalization? The direct installation configuration is as follows:
1. JAVA JDK Installation:
#下载相应的jdk软件包 and then unzip the installation, I have the package name:jdk-7u25-linux-x64.tar.gz tar -zxvf jdk-7u25-linux-x64.tar.gz mkdir -p /usr/java/ #创建java目录mv jdk1.7.0_25/ /usr/local/java/ #修改java目录 # Then configure the environment variables so that the JDK can be referenced anywhere, and the following statement is added to the last side of the configuration: vi /etc/profile : java_home=/usr/local/java java_bin=/usr/local/java/binjre _home=/usr/local/java/jrepath= $PATH:/usr/local/java/bin:/usr/local/java/jre/binclasspath=/usr/local/java/jre/ lib:/usr/local/java/lib:/usr/local/java/jre/lib/charsets.jar #source /etc/profile #使环境变量马上生效 #java --version #查看java版本, see the JDK version asRepresents JAVA JDK installation success.
2, Nginx Installation:
wget http://nginx.org/download/nginx-1.2.6.tar.gz useradd www tar zxvf nginx-1.2.6.tar.gz cd nginx-1.2.6 /./configure--user=www--group=www--prefix=/usr/local/nginx \--with-http_stub_status_module \--WITH-HTTP_SS L_module make && make install #Nginx安装完毕, then use the command:/usr/local/nginx/sbin/nginx-t Test OK, on behalf of Nginx installation success. /usr/local/nginx/sbin/nginx Enter to start Nginx, you can visit http://ip/to see the default page Nginx.
3. Tomcat Installation:
#官方网站下载tomcat: cd /usr/src && tar zxvf apache-tomcat-6.0.30.tar.gz #直接解压就可以使用, unzip to complete execution, Copy two tomcat at a time, named tomcat1 tomcat2 mv apache-tomcat-6.0.30 /usr/local/tomcat1 cp /usr/local/tomcat1 /usr/local/tomcat2 -r #分别修改tomcat1和tomcat2 Ports, Here are three ports that need to be modified, respectively, as follows: shutdown Port:8005 is primarily responsible for initiating the shutdown .       AJP Port:8009 is primarily responsible for AJP equalization (commonly used in Apache and Tomcat integration) http Port:8080 can be accessed directly via Web page (nginx+tomcata consolidation) #注 * If the TOMCAT1 three ports are: 8005 8009 8080&NBSP, then the TOMCAT2 port is +1 on this basis, which is:8006 8010 8081 #一Server, the port cannot be duplicated, otherwise it will error. #修改完端口后, then launch two tomcat, start command for: #如何提示没有这个文件或者权限不足, the tomcat Bin directory is required to give execute permission to the Sh file:chmod o+x *.sh /usr/local/tomcat1/bin/startup.sh /usr/local/ tomcat2/bin/startup.sh #启动后, you can see 6 ports using netstat -tnl , This means that the TOMCAT1 TOMCAT2 successfully started. You can use http://ip:8080 http://ip:8081 to access the Tomcat default page.
#如果需要修改tomcat发布目录为自己制定的目录, you need to make the following adjustments to create two publish directories:
Mkdir-p/usr/webapps/www1mkdir-p/USR/WEBAPPS/WWW2
Edit Vi/usr/local/tomcat1/conf/server.xml Add content to the last previous line:
2. Edit Vi/usr/local/tomcat2/conf/server.xml Add content to the last previous line:
3.TOMCAT1 Publish Directory content:
vim/usr/webapps/www1/index.jsp tomcat_1 JSP Test Page
4.tomcat2 Publish Directory content:
Tomcat_2 JSP Test Page
Then visit http://ip:8080, 8081 to view the test content.
5, Nginx+tomcat Integration:
user www www; worker_processes 8; pid /usr/local/nginx/ nginx.pid; worker_rlimit_nofile 102400; events { use epoll; worker_connections 102400; } http { include mime.types; default_type application/octet-stream; fastcgi_intercept_errors on; charset utf-8; server_names_hash_bucket_size 128; client_header_ buffer_size 4k; large_client_header_buffers 4 32k; client_max_body_size 300m; sendfile on; tcp_nopush&nbSp; on; keepalive_ timeout 60; tcp_nodelay on; client_body_buffer_size 512k; proxy_connect_timeout 5; proxy_read_timeout 60; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; ## #2012 -12-19 change nginx logs log_format main ' $http _x_forwarded_for - $remote _user [$time _local] "$request" " ' $status $body _bytes_sent "$http _referer" ' ' "$http _user_ Agent " $request _TIME  $remote _addr '; upstream web_app { server 127.0.0.1:8080 weight=1 max_fails=2 fail_timeout=30s; server 127.0.0.1:8081 weight=1 max_fails=2 fail_timeout=30s; } ### #chinaapp .sinaapp.com server { listen 80; server_name chinaapp.sinaapp.com; index index.jsp index.html index.htm; #发布目录/data/www root /data/www; location / &nbSp { proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_set_header host $ host; proxy_set_header x-real-ip $remote _addr; proxy_set_header X-Forwarded-For $proxy _add_x_forwarded_for; proxy_pass http://web_app; expires 3d; } } }
#注 * Server segment Proxy_pass defined Web_app needs to be consistent with the Web_app defined in upstream, otherwise the server cannot find a balance.
This article is from the "Ming Linux blog" blog, be sure to keep this source http://zhaijunming5.blog.51cto.com/10668883/1694646
Nginx+tomcat Load Balancing