Use Nginx + Tomcat in Windows to configure Cluster load balancing and nginxtomcat

Source: Internet
Author: User
Tags windows download

Use Nginx + Tomcat in Windows to configure Cluster load balancing and nginxtomcat


Nginx is a lightweight web server/reverse proxy server. Currently, Sina and Netease are all using it in China. Let's talk about my server software environment:

System: windows_server_2008_standard_enterprise_and_datacenter_with_sp2_x64

Currently running Tomcat: Non-installed version of Tomcat 6.0.36

Let's talk about these two key issues. The current problem is that the traffic volume is greatly increased. A single tomcat is no longer capable of load and often times out. As a result, we plan to use nginx to deploy Server Load balancer. Most of the information found on the network is about how to deploy and use nginx in linux, however, in windows, if nginx of linux version is used only for testing, but the actual production environment cannot be used, the following error will be reported:

maximum number of descriptors supported by select() is 1024 while waiting for request

This is because the number of file access handles is limited to 1024, and the response will fail when the traffic volume is large. I have checked a lot of information on the Internet and said that modifying the worker_connections parameter can solve this restriction. Others said that I tried to modify the worker_rlimit_nofile parameter but all failed. I saw a reply in a foreign forum when I was preparing to change other tools. I don't remember the address. I said there was a dedicated windows version of nginx, the restrictions on file handle data have been modified. After the download result, the configuration is successfully run. You only need to download to the correct version configuration or so easy. The following is the configuration download process ~~

Nginx for windows Official Website: http://nginx-win.ecsds.eu/

Nginx for windows download address: http://nginx-win.ecsds.eu/download/

I downloaded the nginx 1.7.7.1 WhiteRabbit.zip version. I am afraid it is unstable. After downloading the package, decompress the installation package, which contains a brief update information and Installation Guide Readme nginx-win version.txt. The key information is as follows:

*** Default installation instructions;* New: unzip this version with folder structure* Old: overwrite with this version* Check nginx.conf, nginx-org.conf and nginx-win.conf* Windows optimization registry file: check your current values BEFORE setting the new ones
Find the nginx-win.conf In the conf folder, copy it and rename it nginx. conf, and configure it in this file. My configuration file is as follows:

# User nobody; # multiple workers works! # Worker Process count: This value must be configured based on the number of CPU cores on the server. For example, the cpu of a 6-Core 12-thread can be set to 6 or 12. Worker_processes 6; # path to storing error logs # error_log logs/error. log; # error_log logs/error. log notice; # error_log logs/error. log info; # pid logs/nginx. pid; events {# set the maximum number of connections opened by a single process at the same time. This value is larger and can accept more connections. Of course, this requires cpu and memory support ~~ Worker_connections 32768; # max value 32768, nginx reconfiguring connections + registry optimization = # this. value * 20 = max concurrent connections currently tested with one worker # C1000K shocould be possible depending there is enough ram/cpu power # multi_accept on ;} http {# include/nginx/conf/naxsi_core.rules; include mime. types; default_type application/octet-stream; # log_format main '$ remote_addr: $ Remote_port-$ remote_user [$ time_local] "$ request" '#' $ status $ body_bytes_sent "$ http_referer" '#' "$ http_user_agent" "$ http_x_forwarded_for "'; # access_log logs/access. log main; ## loadbalancing PHP # upstream myLoadBalancer {# server 127.0.0.1: 9001 weight = 1 fail_timeout = 5; # server 127.0.0.1: 9002 weight = 1 fail_timeout = 5; # server 127.0.0.1: 9003 weight = 1 fail_timeout = 5; # server 127.0.0.1: 9004 we Ight = 1 fail_timeout = 5; # server 127.0.0.1: 9005 weight = 1 fail_timeout = 5; # server 127.0.0.1: 9006 weight = 1 fail_timeout = 5; # server 127.0.0.1: 9007 weight = 1 fail_timeout = 5; # server 127.0.0.1: 9008 weight = 1 fail_timeout = 5; # server 127.0.0.1: 9009 weight = 1 fail_timeout = 5; # server 127.0.0.1: 9010 weight = 1 fail_timeout = 5; # least_conn ;#}# set tomcat server information here, And tomcat can also be different from the same host. Two tomcat services are set here, with a proportion. Replace localhost with the server IP upstream localhost {# ip_hash; server 127.0.0.1: 9010 weight = 1; server 127.0.0.1: 9020 weight = 1;} sendfile off; # tcp_nopush on; server_names_hash_bucket_size 128; # Start: Timeouts ## client_body_timeout 10; client_header_timeout 10; keepalive_timeout 80; send_timeout 10; keepalive_requests 10; ## End: Timeouts ### gzip on; server {# This is critical ~~ It is the port listened to by nginx ~~ Listen 8080; server_name localhost; # charset koi8-r; # access_log logs/host. access. log main; # For Naxsi remove the single # line for learn mode, or the # lines for full WAF mode location/{# include/nginx/conf/mysite. rules; # see also http block naxsi include line ## SecRulesEnabled; ## DeniedUrl "/RequestDenied" ;## CheckRule "$ SQL> = 8" BLOCK; # CheckRule "$ RFI> = 8" BLOCK; ## CheckRule "$ TRAVERSA L> = 4 "BLOCK; # CheckRule" $ XSS> = 8 "BLOCK; proxy_pass http: // localhost; root html; index index.html index.htm ;} # For Naxsi remove the ## lines for full WAF mode, redirect location block used by naxsi ## location/RequestDenied {## return 412; ##}## Lua examples! # Location/robots.txt {# rewrite_by_lua '# if ngx. var. http_host ~ = "Localhost" then # return ngx.exe c ("/robots_disallow.txt"); # end # ';#}# error_page 404/404 .html; # redirect server error pages to the static page/50x.html # error_page 500 502 503 504/50 x.html; location =/50x.html {root html;} # proxy the PHP scripts to Apache listening on 127.0.0.1: 80 ## location ~ \. Php $ {# proxy_pass http: // 127.0.0.1; #}# pass the PHP scripts to FastCGI server listening on 127.0.0.1: 9000 # location ~ \. Php $ {# root html; # fastcgi_pass 127.0.0.1: 9000; # single backend process # fastcgi_pass myLoadBalancer; # or multiple, see example above # fastcgi_index index. php; # fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name; # include fastcgi_params; #}# deny access. htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\. Ht {# deny all ;#}# another virtual host using mix of IP-, name-, and port-based configuration # server {# listen 8000; # listen somename: 8080; # server_name somename alias another. alias; # location/{# root html; # index index.html index.htm; #}#}# HTTPS server # server {# listen 443 ssl spdy; # server_name localhost; # ssl on; # ssl_certificate cert. pem; # ssl_certificate_key cer T. key; # Listen 5 m; # comment On; # ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; # comment ECDH + AESGCM: DH + AESGCM: ECDH + AES256: DH + AES256: ECDH + AES128: DH + AES: ECDH + 3DES: DH + 3DES: RSA + AESGCM: RSA + AES: RSA + 3DES :! ANULL :! ENULL :! MD5 :! DSS; # location/{# root html; # index index.html index.htm ;#}#}}


The configuration of Tomcat is relatively simple, that is, copy and modify the three ports. Baidu.

After configuring nginx.exe and tomcat, you can verify the configuration.

Nginx start control I use the script of a buddy on the Internet. The address is as follows:

Http://feitianbenyue.iteye.com/blog/1989868






Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.