Sunteți pe pagina 1din 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

S-ar putea să vă placă și