Nginx+tomcat build high-performance load Balancing cluster-windows local beta

Source: Internet
Author: User
Tags sendfile

First, install Tomcat and Nginx

First install two apache-tomcat-8.0.41,:http://tomcat.apache.org

and install a nginx-1.13.0,http://nginx.org/en/download.html

are green version, directly decompression can be used, do not need to do environment variables and other configuration.

Here is a small problem: the company's computer environment variables with the JDK6, so my Tomcat8 start when the black window flashed, JDK version does not match the reason, the jdk6 replaced Jdk8, Tomcat8 normal start.

Second, modify the Tomcat port number

My first Tomcat is the default, just modify the second tomcat, make sure two Tomcat can start at the same time, need to modify the port number in the following three places (O (∩_∩) o I just added 1~ in the default multi-slogan):

Third, modify Tomcat's default page to identify which Tomcat is accessed

Another tomcat here is to add the =====TOMCAT1

Four, modify the configuration of Nginx

Configuration content

1 #user Nobody;2 worker_processes 1; #工作进程的个数, generally consistent with the number of CPU cores on the computer3 4 #error_log Logs/error.log;5 #error_log logs/error.log notice;6 #error_log logs/error.log info;7 8 #pid logs/nginx.pid;9 Ten  One Events { A worker_connections; #单个进程最大连接数 (maximum number of connections = number of connections * Number of processes) - } -  the  - http { - include mime.types; #文件扩展名与文件类型映射表 - default_type application/octet-stream; #默认文件类型 +  - #log_format main ' $remote _addr-$remote _user [$time _local] "$request" ' + # ' $status $body _bytes_sent ' $http _referer ' A # ' "$http _user_agent" "$http _x_forwarded_for" '; at  - #access_log Logs/access.log main; -  - sendfile on; #开启高效文件传输模式, the sendfile instruction specifies whether Nginx calls the Sendfile function to output the file, - #对于普通应用设为 on, if used for downloading applications such as disk IO heavy load applications, can be set to OFF, - #以平衡磁盘与网络I/O processing speed to reduce the load on the system. Note: If the picture does not appear normal, change this to off.  in #tcp_nopush on; -  to #keepalive_timeout 0; + keepalive_timeout; #长连接超时时间, Unit is seconds -  the #gzip on; #启用Gizp压缩 *  $ #服务器的集群Panax Notoginseng upstream netitcast.com {#服务器集群名字 - server 127.0.0.1:8080 weight=1; #服务器配置 weight is the meaning of weight, the larger the weight, the greater the probability of distribution.  the server 127.0.0.1:8081 weight=2;  +     }  A  the #当前的Nginx的配置 + server { - Listen, #监听80端口, can be changed to another port $ server_name localhost; #当前服务的域名 $  - #charset koi8-r; -  the #access_log Logs/host.access.log main; - Wuyi Location /{ the root html; - index index.html index.htm; Wu Proxy_pass http://netitcast.com;  - proxy_redirect default; About         } $  - #error_page 404/404.html; -  - # REDIRECT Server error pages to the static page/50x.html A         # + Error_page 502 503 504/50x.html; the Location =/50x.html { - root html; $         } the  the # Proxy The PHP scripts to Apache listening on 127.0.0.1:80 the         # the #location ~ \.php$ { - # Proxy_pass http://127.0.0.1; in         #} the  the # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 About         # the #location ~ \.php$ { the # root HTML; the # Fastcgi_pass 127.0.0.1:9000; + # Fastcgi_index index.php; - # Fastcgi_param Script_filename/scripts$fastcgi_script_name; the # include fastcgi_params;Bayi         #} the  the # Deny access to. htaccess files, if Apache ' s document Root - # concurs with Nginx ' s one -         # the #location ~/\.ht { the # deny all; the         #} the     } -  the  the # Another virtual host using mix of ip-, name-, and port-based configuration the     #94 #server { the # Listen 8000; the # listen somename:8080; the # server_name Somename alias Another.alias;98  About # location/{ - # root HTML;101 # index index.html index.htm;102     #    }103     #}104  the 106 # HTTPS Server107     #108 #server {109 # Listen 443 SSL; the # server_name localhost;111  the # ssl_certificate Cert.pem;113 # Ssl_certificate_key Cert.key; the  the # Ssl_session_cache shared:ssl:1m; the # ssl_session_timeout 5m;117 118 # ssl_ciphers high:!anull:! MD5;119 # ssl_prefer_server_ciphers on; - 121 # location/{122 # root HTML;123 # index index.html index.htm;124     #    } the     #}126 127}

In fact, the following two places have been modified:

Five, start testing

Launch two Tomcat directly via Startup.bat. There will be two black windows with Tomcat's boot log.

Then through the Nginx directory of the Nginx.exe to start Nginx.

Vi. test Results

As shown, the browser accesses localhost, constantly refreshed, access to Tomcat will switch back and forth in 1 and 2, the probability of switching is determined by the configured weights.

Nginx+tomcat build high-performance load Balancing cluster-windows local beta

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.