Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx+Tomcat High performance load balancing Cluster Building tutorial

2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Nginx is a high performance HTTP server / reverse proxy server and email (IMAP/POP3) proxy server. It occupies less memory and has strong concurrency ability, so it performs better in the same type of web server. Nginx can be compiled and run on most Unix Linux OS, and there is a portable version of Windows. In general, for new sites, it is recommended to use the latest stable version as the production version.

The maximum amount of online access supported by a single Tomcat is about 500. it is impossible for a Tomcat to inform it that it supports more visits. Here we use cluster deployment, using multiple Tomcat and reverse proxy using Nginx.

The architecture is as follows:

Preparatory work

Apache-tomcat-7.0.61

Nginx-1.12.2

Redis-x64-3.2.100

To simplify the example, I will only talk about the deployment and integration of Nginx+Tomcat.

Nginx installation

(1) go to the official website to download the latest stable version of Windows Nigx (version 1.12.2 I use). Official website

(2) decompress to any directory on the disk. Here I decompress in F:\ nginx-1.12.2

(3) start the service: start nginx.exe

Stop service: nginx-s stop

Reload configuration: nginx-s reload

Modify nginx.conf

1. Number of processes and maximum number of connections per process

The number of nginx processes, which is recommended to be equal to the total number of CPU cores, the maximum number of connections per process. Then the maximum number of connections to the server = the number of connections * processes

Basic configuration of 2.Nginx

Generally speaking, the listening ports are http ports: there can be multiple 80 domain names, separated by spaces. For example, server_name www.sohu.com baidu,com

3. Basic configuration of load balancer list

Location / {}: what kind of suffix to request for load balancer? if we want to load balance all files with the aspx suffix, we can write: location ~. *\ .aspx ${} proxy_pass: the request is directed to the custom server list. Here, we turn the requests to the load balancer server list identified as http://joannayan.com. Weight weight, the higher the weight, the greater the probability of being assigned. You can define the weight according to the machine configuration (if a server has a good hardware configuration and can handle more requests, you can set a higher weight; and a server with a poor hardware configuration, so you can configure the weight of the former as weight=2 and the poor configuration of the latter as weight=1).

test

Deploy the TestNginx.war Web project to the Tomcat servers of the two machines (in order to distinguish between accessing different Web servers, the TestNginx project deployed on the two machines is slightly different on the page).

Start Tomcat on both machines, and start nginx.

Visit nginx: http://localhost/TestNginx

Refresh, and then visit:

Due to the different weights, the "5.20 server" is more likely to be displayed in the process of constantly refreshing the page.

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report