How to set up NGINX Plus as the load balancer for a JIRA Data Center cluster
The content on this page relates to platforms which are not supported for JIRA Applications. Consequently, Atlassian cannot guarantee providing any support for it. Please be aware that this material is provided for your information only and using it is done so at your own risk.
This configuration only works with NGINX Plus, the paid version of NGINX. The free version does not support cookie-based session-affinity.
Description
JIRA Data Center needs a load balancer to run in front of it to distribute the incoming requests between each node. The load balancer must support cookie-based session-affinity. NGINX Plus can be set up to provide this for JIRA Data Center, using a configuration similar to the one below. You still need to follow the full installation guide available at Installing JIRA Data Center. For more details on the configuration of a load balancer in NGINX Plus, see the page Application Load Balancing with NGINX Plus and the Upstream module documentation, on the NGINX website.
Sample NGINX Configuration
The load balancer configuration below is based on NGINX's documentation Load Balancing Apache Tomcat Servers with NGINX Open Source and NGINX Plus. Please note that it also requires some Jira (Tomcat) configuration, which will be detailed below.
pid /var/run/nginx.pid;
events {}
http {
# Search the cookie named JSESSIONID for data after the final ‘.’, and store that
# in a variable named $route_cookie
map $cookie_jsessionid $route_cookie {
~.+\.(?P<route>\w+)$ $route;
}
# Search the URL for a trailing jsessionid parameter, and store the value after the final ‘.’
# in a variable named $route_uri
map $request_uri $route_uri {
~jsessionid=.+\.(?P<route>\w+)$ $route;
}
upstream jiracluster {
server jira1.internal.atlassian.com:8080 route=node1;
server jira2.internal.atlassian.com:8080 route=node2;
sticky route $route_cookie $route_uri;
}
server {
listen 80;
server_name MyCompanyServer;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://jiracluster;
}
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
}
}
Jira (Tomcat) Configuration
In addition to the above Nginx configuration, we also need to configure Tomcat to add a node identifier to its JSESSIONID session cookie. This can be done by editing JIRA_INSTALL
/conf/server.xml
and changing:
<Engine name="Catalina" defaultHost="localhost">
to:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="node1">
where the value of jvmRoute matches the Nginx upstream server's route parameter. In the Nginx sample configuration above, jira1.internal.atlassian.com:8080 would need to set jvmRoute="node1", while jira2.internal.atlassian.com:8080 would need to set jvmRoute="node2".
After making this change, Jira will need to be restarted on each node.