Configure Nginx + Tomcat Load Balancing (supports Session sharing) In Debian 6 <> 1. Configure the environment. <> 1. <> 2 <> 2 <> 2 <> 2 <> 2 <> 2 <> 2 <> 2 <> 2 <> 2 <> 2 <> 2 <> 2 <> 2 <> 2. Srv76 Install Nginx on.
<> 1. Run the following command to install the required software package for compiling Nginx. Srv76 :~ # Apt-get upgradesrv76 :~ # Apt-get install zlibc libpcre ++-dev bzip2 autoconf automake g ++ gcc \ make libssl-dev libpcre3-dev build-essential <> 2. Use the following command to download and compile Nginx and nginx_upstream_jvm_route. Srv76 :~ # Adduser -- system -- no-create-home -- disabled-login \ -- disabled-password -- group nginxsrv76 :~ # Cd/usr/srcsrv76: src # wget http://nginx.org/download/nginx-1.0.4.tar.gzsrv76:src# svn checkout http://nginx-upstream-jvm-route.googlecode.com/svn/trunk/ nginx-upstream-jvm-route-read-onlysrv76: src # tar-xvzf nginx-1.0.4.tar.gzsrv76: src # cd nginx-1.0.4srv76: nginx-1.0.4 # patch-p0 <.. /nginx-upstream-jvm-route-read-only/jvm_route.patchsrv76: nginx-1.0.4 #. /configure -- user = nginx -- group = nginx -- pref Ix =/usr/local/nginx \ -- with-http_stub_status_module -- with-http_ssl_module \ -- with-pcre -- add-module = .. /nginx-upstream-jvm-route-read-onlysrv76: nginx-1.0.4 # make & make install <> 3. Use the following command to configure the Nginx Service Startup command. Srv76 :~ # Chmod + x/etc/init. d/nginxsrv76 :~ #/Usr/sbin/update-rc.d-f nginx defaultssrv76 :~ # Ln-s/usr/local/nginx/sbin/*/sbin/srv76 :~ # Mkdir/var/log/nginxsrv76 :~ # Chgrp nginx/var/log/nginx/srv76 :~ # Chmod g + w/var/log/nginx/<> 3. install and configure Tomcat and Java. <> 1. Run the following command on Srv76 and Srv77 to install Tomcat and Java. Srv76 :~ # Apt-get install libmysql-java tomcat6 libservlet2.5-java libtomcat6-java \ mysql-server sun-java6-jdk sun-java6-bin tomcat6-admin sun-java6-jre \ <> 2, in Srv76 will/etc/tomcat6/server. in the xml file, modify "<Engine name =" Catalina "defaultHost =" localhost ">" to the following content. <Engine name = "Catalina" defaultHost = "localhost" jvmRoute = "srv76"> <> 3. Set/etc/tomcat6/server on Srv77. in the xml file, modify "<Engine name =" Catalina "defaultHost =" localhost ">" to the following content. <Engine name = "Catalina" defaultHost = "localhost" jvmRoute = "srv77"> <> 4. Run the following command on Srv76 and Srv77 to restart Tomcat. Srv76 :~ #/Etc/init. d/tomcat6 restart <> 4. Modify the following content in the/usr/local/nginx/conf/nginx. conf file. User nginx; worker_processes 30; error_log/var/log/nginx/nginx_error.log crit; pid/usr/local/nginx. pid; worker_rlimit_nofile 51200; events {use epoll; worker_connections 65535;} http {upstream backend {server 192.168.159.76: 8080 srun_id = srv76; server 192.168.159.77: 8080 srun_id = srv77; jvm_route $ cookie_JSESSIONID | sessionid reverse;} include mime. types; default_type application/octet-str Eam; charset UTF-8; Cost 128; Cost 32 k; cost 4 32 k; client_max_body_size 20 m; limit_rate 1024 k; sendfile on; server_tokens off; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64 k; fastcgi_buffers 4 64 k; fastcgi_busy_buffers _ Size 128 k; fastcgi_temp_file_write_size 128 k; gzip on; gzip_min_length 1 k; gzip_buffers 4 16 k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain text/css application/x-javascript application/xml; gzip_vary on; gzip_disable "MSIE [1-6] \. (?!. * SV1) "; server {listen 80; server_name 192.168.159.76; index index.html index.htm index. jsp; root/var/www; location/{proxy_pass http: // backend/; proxy_redirect off; proxy_set_header X-Forwarded-For $ response; proxy_set_header X-Real-IP $ remote_addr; proxy_set_header Host $ http_host;} location ~. * \. (Gif | jpg | jpeg | png | bmp | swf) $ {expires 30d;} location ~. * \. (Js | css )? $ {Expires 1 h;} location/Nginxstatus {stub_status on; access_log off ;} log_format access' $ remote_addr-$ remote_user [$ time_local] "$ request" ''$ status $ body_bytes_sent" $ http_referer "'' "$ http_user_agent" $ http_x_forwarded_for '; access_log/var/log/nginx/jsp. access. log ;}}
This article is from the blog of "sharing with one another ".