Test environment: only resin server1 IP Address: 192.168.6.121server2 IP Address: 192.168.6.162 is installed on the nginx + resinserver2 server on the server1 server.Installation steps:1. install and configure nginx + on server1Nginx_upstream_jvm_routeShell $> wget-c http://sysoev.ru/nginx/nginx-0.7.61.tar.gzshell $> svn checkoutHttp: // Nginx-upstream-jvm-route.googlecode.com/svn/trunk/ nginx-upstream-jvm-route-read-onlyshell $> tar zxvf nginx-0.7.61shell $> cd nginx-0.7.61shell $> patch-p0 <.. /nginx-upstream-jvm-route-read-only/jvm_route.patchshell $> useradd wwwshell $>. /configure -- user = www -- group = www -- prefix =/usr/local/webserver/nginx -- with-http_stub_status_module -- with-http_ssl_module -- add-module =/root/nginx-upstream-jvm-route -read-onlyshell $> makeshell $> make install2. install resin on the two machines respectively.### Modify the environment variable ### shell $> vim/etc/profile ### enter the following in umask 022 ### JAVA_HOME =/usr/lib/jvm/java -6-sun
Export JAVA_HOMEJRE_HOME = "$ {JAVA_HOME}"/jre
Export JRE_HOMECLASSPATH =.: "$ {JAVA_HOME}"/lib/tools. jar: "$ {JAVA_HOME}"/lib/dt. jar $ {RESIN_HOME} "/lib/resin. jar: "$ {CLASSPATH}
Export CLASSPATHRESIN_HOME =/usr/local/resin
Export RESIN_HOME
PATH = "$ {JAVA_HOME}"/bin: "$ {PATH }"
Export PATHshell $> wget-c http://www.caucho.com/download/resin-3.1.9.tar.gzshell $> tar zxvf resin-3.1.9.tar.gzshell $> cd resin-3.1.9shell $>./configure -- prefix =/usr/local/resinshell $> makeshell $> make install3. Configure the resin of the two machinesShell $> cd/usr/local/resinshell $> cd confshell $> vim resin. conf # search for <Http id = "" port = "8080"/>
</Server> <server id = "B" address = "192.168.6.121" port = "6801"> <! -- Server2 address = 192.168.6.162 -->
<Http id = "" port = "8081"/>
</Server>
Shell $> cd/usr/local/resin/webapps/ROOT/shell $> mv index. jsp index. jsp. bakshell $> vim index. jsp ## enter the following content <% @ page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%>
<%
%> <Html>
<Head>
</Head>
<Body>
121 <! -- Server2: 162 -->
<Br/>
<% Out. print (request. getSession (); %> <! -- Output session -->
<Br/>
<% Out. println (request. getHeader ("Cookie"); %>
<! -- Output Cookie --> </body>
</Html> ### restart the resin service ######## server1 server ##### shell $>/usr/local/resin/bin/httpd. sh-server a start ### note that if the environment variable is not modified, an error is reported ### server2 server #### shell $>/usr/local/resin/bin/httpd. sh-server B start ### note that server2 server only starts server_id B ###4. Integrate ngxin resinShell $> cd/usr/local/nginx/confshell $> mv nginx. conf nginx. bakshell $> vim nginx. conf ## configuration ### user www; worker_processes 4; error_log logs/nginx_error.log crit; pid/usr/local/nginx. pid; # Specifies the value for maximum file descriptors that can be opened by this process.
Worker_rlimit_nofile 51200; events
{
Use epoll;
Worker_connections 2048;
} Http
{
Upstream backend {
Server 192.168.6.121: 8080 srun_id = a; #### here srun_id = a corresponds to the server id = "a" in the server1 resin Configuration"
Server 192.168.6.162: 8081 srun_id = B #### here srun_id = B Corresponds to server id = "B" jvm_route $ cookie_JSESSIONID | sessionid in server2 resin configuration;
} Include mime. types;
Default_type application/octet-stream; # charset gb2312;
Charset UTF-8; server_names_hash_bucket_size 128;
Client_header_buffer_size 32 k;
Large_client_header_buffers 4 32 k;
Client_max_body_size 20 m;
Limit_rate 1024 k; sendfile on;
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.0;
Gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_vary on; # limit_zone crawler $ binary_remote_addr 10 m; server
{
Listen 80;
Server_name 192.168.6.121;
Index index.html index.htm index. jsp;
Root/var/www;
Location ~ . * \. Jsp $
{
Proxy_pass http: // backend;
Proxy_redirect off;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
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/stu {
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 off;
}
}
5. Test. Open the browser and enter http: // 192.168.6.121/index. jsp.
Session shows that aXXXXX accesses the 121 server, that is, server1, because it is the first access, so the Cookie is not obtained. refresh it and check whether it will access 162 server2.
After refresh N times, it is still 121, that is, the patch takes effect, and the cookie value is also obtained. To test, I opened another Firefox browser because of session and cookie issues.) enter the URL:
The display is 162. The session value starts with bXXX. After refresh N times:
Still 162 server 2 server !! If you have any questions during the test, you can remove the srun_id = a srun_id = B in the nginx configuration file. Then, you will know that the page is accessed by polling !! The patch I uploaded is decompressed on linux. Because 51cto does not support the gz format, I changed the suffix, run shell $> tar zxvf nginx-upstream-jvm-route-read-only.rar on linux!
The solution for tomcat is README:1. For resin
Upstream backend {
Server 192.168.0.100 srun_id =;
Server 192.168.0.101 srun_id = B;
Server 192.168.0.102 srun_id = c;
Server 192.168.0.103 srun_id = d; jvm_route $ cookie_JSESSIONID | sessionid;
}
2. For tomcat
Upstream backend {
Server 192.168.0.100 srun_id =;
Server 192.168.0.101 srun_id = B;
Server 192.168.0.102 srun_id = c;
Server 192.168.0.103 srun_id = d;
Jvm_route $ cookie_JSESSIONID | sessionid reverse;
}