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

How to achieve High concurrency in Nginx+Tomcat

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is about how Nginx+Tomcat achieves high concurrency. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Nginx is a lightweight Web server / reverse proxy server and email (IMAP/POP3) proxy server. In the Web architecture of Java, Tomcat and Nginx are usually used to cooperate. As a reverse proxy server, Nginx can balance the load of the Tomcat server in the background, and it can also let Nginx handle static page requests and Tomcat handle JSP page requests to achieve the purpose of separation of movement and movement.

Nginx configuration normal tomcat Jump

Configure the request forwarding address through proxy_pass. That is, when accessing port 8010 of localhost, the request will jump to port 8080 of localhost.

Static and dynamic separation configuration

Above we directly tried a small example, let nginx forward, that is, the so-called reverse proxy. But in fact, our requirements will not be like this. We need to filter by file type. For example, jsp is directly processed by tomcat, because nginx is not a servlet container, so there is no way to handle JSP, while html,js,css, which does not need to be processed, is directly cached to nginx.

At this time, the element location is mainly used, and some regular elements are involved, but it is not difficult. The specific configuration is as follows:

If you enter localhost:8010 directly at this time, you will report a 404 error. However, if you enter localhost:8010/index.jsp, you can also jump to the tomcat home page.

Load balancing configuration

When one server fails, we need to automatically redirect the request to another server. How to configure this requirement? It is also convenient to use Nginx. The specific configuration is as follows:

Note that a weight attribute is also added above, which indicates the weight of each server accessed. The higher the weight, the higher the probability of access.

Other configuration

Thank you for reading! This is the end of the article on "how to achieve high concurrency in Nginx+Tomcat". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

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

Development

Wechat

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

12
Report