0% found this document useful (0 votes)
393 views

NGINX - Configuration

This document provides instructions for configuring NGINX as a load balancer and proxy for multiple Tomcat application servers using the AJP protocol. It describes downloading and compiling NGINX with the AJP module. The configuration directs requests to backend Tomcat instances defined in an upstream block based on their IP address and AJP port. Specific parameters like ajp_keep_conn and ajp_pass are required in the server block to enable AJP proxying. The configuration is tested and NGINX restarted to load balance requests across the Tomcat servers.

Uploaded by

Prasad Lele
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
393 views

NGINX - Configuration

This document provides instructions for configuring NGINX as a load balancer and proxy for multiple Tomcat application servers using the AJP protocol. It describes downloading and compiling NGINX with the AJP module. The configuration directs requests to backend Tomcat instances defined in an upstream block based on their IP address and AJP port. Specific parameters like ajp_keep_conn and ajp_pass are required in the server block to enable AJP proxying. The configuration is tested and NGINX restarted to load balance requests across the Tomcat servers.

Uploaded by

Prasad Lele
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

NGINX ############################################### Configuring NGINX web server ################################################ 1: Download and install tomcat instances on the server 2: Download

Nginx (http://linux.softpedia.com/get/Internet/Proxy/nginx-28901.shtml) 3: Untar the source and compile it. 4: Now make a backup of original config of nginx. 5: Now open the nginx conf file (for me its under /usr/local/nginx/conf). 6: Remove every thing in it and make it blank. 7: Now just add the below basic parameters in it. Just a plain webserver. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; access_log logs/access.log combined; sendfile on; keepalive_timeout 65; server { listen 80; server_name testmach; location / { root /var/www/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } } +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8: Now test and restart nginx /usr/local/nginx/sbin/nginx -t && /usr/local/nginx/sbin/nginx -s restart 9: Check if your site is accessible ############################################### Load balancing in NGINX (using mod_proxy) ################################################ Page 1

NGINX 1: Download and install tomcat instances on the server 2: Download Nginx (http://linux.softpedia.com/get/Internet/Proxy/nginx-28901.shtml) 3: Untar the source and compile it. 4: Now make a backup of original config of nginx. 5: Now open the orignal config file and remove the default http config from the config file and add the below parameters in nginx.conf +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ http { upstream IP/HOSTNAME/NAME { server IP OF SERVER1:PORT; #weight=3 server IP OF SERVER2:PORT; } server { listen 80; server_name IP OF NGINX SERVER; location / { proxy_pass http://IPOFNGINXSERVER/HOSTNAME; } } } +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6: Test the config with the command ./nginx -t 7: If test is successfull, start the server 8: Now test the load balancing using nginx IP. ############################################### Integrations of tomcat with NGINX using AJP protocol ################################################ Firstly we need to re-compile nginx to add the ajp module. Below are the compilation steps 1: Download and unzip the module in a different directory.(https://github.com/yaoweibin/nginx_ajp_module - click on zip) 2: Now go to the nginx source code directory (not module directory) and run the below command to re-compile nginx with mod_jk module. ./configure --add-module=/path/to/nginx_ajp_module make && make install 3: Now open the nginx conf file and remove all the default config and add below parameters under http directive http { Page 2 + + + + + + + + + + + + + + +

NGINX upstream tomcat { server instance1_ip:ajp_port srun_id="tom1"; <----------------------------------------------- This has to be specified for jvm_route in tomcat config file under AJP section (default value is jvm1) server instance2_ip:ajp_port srun_id="tom2"; server instance3_ip:ajp_port srun_id="tom3"; jvm_route $cookie_JSESSIONID reverse; keepalive 20; } server { listen 80; # server_name tomcat; location / { ajp_keep_conn on; <--------------------------~\ |-------------------------------------------------- These two parametes are necessary. ajp_pass tomcat; <--------------------------~/ } } } 4: now test the config file but $nginx-dir/sbin/nginx -t 5: If tests are successfull, start/restart nginx and check if you are able to see the tomcat page Note: Please ensure that you close each brace bracket before restart, else it will give and error.

Page 3

You might also like