Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tbje/nginx-upstream-jvm-route
Modified Nginx Upstream Jvm Route (yaoweibin)
https://github.com/tbje/nginx-upstream-jvm-route
Last synced: 3 months ago
JSON representation
Modified Nginx Upstream Jvm Route (yaoweibin)
- Host: GitHub
- URL: https://github.com/tbje/nginx-upstream-jvm-route
- Owner: tbje
- Created: 2010-07-11T14:55:06.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2010-07-12T10:35:58.000Z (over 14 years ago)
- Last Synced: 2024-08-05T19:34:45.679Z (7 months ago)
- Language: C
- Homepage: http://code.google.com/p/nginx-upstream-jvm-route/
- Size: 105 KB
- Stars: 12
- Watchers: 5
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README
- Changelog: CHANGES
Awesome Lists containing this project
README
nginx_upstream_jvm_route
-------This module achieves session stickiness with the session cookie. If the session is not in the cookie or URL, the module will be a normal Round-Robin upstream module.
INSTALLATION
cd nginx-0.7.59 # or whatever
patch -p0 < /path/to/this/directory/jvm_route.patch
compile nginx with the following addition option:--add-module=/path/to/this/directory
DIRECTIVES
jvm_route
syntax: jvm_route $cookie_SESSION_COOKIE[|session_url] [reverse]
default: none
context: upstream
description:
'$cookie_SESSION_COOKIE' specifies the session cookie name(0.7.24+). 'session_url' specifies a different session name in the URL when the client does not accept a cookie. The session name is case-insensitive. In this module, if it does not find the session_url, it will use the session cookie name instead. So if the session name in cookie is the name with its in URL, you don't need give the session_url name.
With scanning this cookie, the module will send the request to right backend server. As far as I know, the resin's srun_id name is in the head of cookie. For example, requests with cookie value 'a***' are always sent to the server with the srun_id of 'a'. But tomcat's JSESSIONID is opposite, which is like '***.a'. The parameter of 'reverse' specifies the cookie scanned from tail to head.
If the request fails to be sent to the chosen backend server, It will try another server with the Round-Robin mode until all the upstream servers tried. The directive proxy_next_upstream can specify in what cases the request will be transmitted to the next server. If you want to force the session sticky, you can set 'proxy_next_upstream off'.server
Every syntax is the same with the official directive except the parameter of 'srun_id' which identified the backend JVM's name by cookie. The default srun_id's value is 'a';
EXAMPLE
1.For resin with nginx
upstream backend {
server 192.168.0.100 srun_id=a;
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;
}For all resin servers' configure:
And start each resin instances like this:
server a
shell $> /usr/local/resin/bin/httpd.sh -server a startserver b
shell $> /usr/local/resin/bin/httpd.sh -server b startserver c
shell $> /usr/local/resin/bin/httpd.sh -server c startserver d
shell $> /usr/local/resin/bin/httpd.sh -server d start2.For tomcat with nginx
upstream backend {
server 192.168.0.100 srun_id=a;
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 reverse;
}Each tomcats' configure:
Tomcat a:
Tomcat b:
Tomcat c:
Tomcat d:
3. A simple java test page
index.jsp<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
$your_jvm_name
<%out.print(request.getSession()) ;%>
<%out.println(request.getHeader("Cookie")) %>Note: This is a third-party module. And you need careful test before using this module in your product environment.
Questions/patches may be directed to Weibin Yao, [email protected].