Hi this is my fifth part of the Tomcat Clustering Series. In this post we are going to discuss how to replace Apache httpd load balancer to Nginx as a load balancer. [Check the video below for better understanding]
here if location / is already present, then remove and add this new one.
here proxy_pass directive, proxifier(forward) the requests to upstream servers. here tomcatcluster is name of the upstream block and we used http protocol to forward the request.
that's it. Load balancer is ready.
now start the tomcat instances based on my previous post (session replication). then start nginx.
now access http://localhost.
now nginx forward the request in round robin fashion to back-end servers. all servers have the session, so it can able to process the request
This is same as non-sticky session method we used in my previous posts.
If we want sticky session, then nginx directly not provide, but some 3rd party patches are available. but nginx provide ip_hash directive. Its forward all request from single IP to same tomcat like sticky session. But sticky session works based on cookie (session). but ip_hash is based on IP address of client.
If u want to configure ip_hash, then modify the upstream block, add ip_hash