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

Which is better, Apache HTTP or Nginx engine?

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

Share

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

Today, the editor will share with you which better related knowledge points of Apache HTTP and Nginx engine, the content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.

HTTP middleware

When we enter a web page link in the browser, the browser sends a request to the corresponding server based on the HTTP (s) transport protocol. After receiving the corresponding request, the server processes it and returns the corresponding information to the browser. Then the browser parses the content in the http and displays it in the form of a web page.

The server is responsible for receiving the request and returning the corresponding data after processing, which can be subdivided into the service part that handles the http connection and the application part that executes the service content (WordPress uses PHP to generate the required pages, which belongs to the application part)

No matter what kind of application the application part executes, the part dealing with http connections is almost the same, so there are middleware specifically dealing with http connections, and the most common ones are Apache and Nginx.

Apache

The official name is "Apache HTTP Server", is an open source HTTP server middleware, was born in 1995, was once the leader in the field of HTTP services, with a large number of users and rich community resources. One of the advantages of Apache is that it is easy to integrate with CMS software such as Wordpress, and you can build a CMS-based website with simple settings.

Internal processing Model of Apache

In terms of internal structure, Apache adopts a multi-process approach, and each connection opens up a process for the connection, dedicated to processing requests on the connection until the connection ends. The benefits of this are:

Connections from different clients will be corresponding immediately and will not interfere with each other, and will not cause other connections to go unresponsive because one service takes a long time.

But the disadvantages are also obvious:

When there are a large number of simultaneous visits, Apache will build a large number of processes and take up too much memory resources.

Scheduling between a large number of threads will also result in a lot of waste of CPU processing power.

As a result, there is a problem called C10K, C is the client (Client), 10K refers to 10,000, that is, no matter how high the performance of the server and the network bandwidth, Apache is difficult to handle more than 10,000 connections at the same time.

Nginx

Pronounced Engine-X, which, like Apache, is open source middleware for HTTP services, was born in 2004. Nginx has a shorter history than Apache, but because it is a latecomer, Nginx learned the lessons of Apache, considered the efficiency of dealing with a large number of connections at the beginning of its design, and solved problems such as C10K that arise with the growth of the Internet.

Internal processing Model of Nginx

Nginx uses a non-blocking IO and an asynchronous message-driven approach, using loops to process connection requests in queues in a thread called worker. According to the hardware situation, multiple worker threads can be set to make full use of the core resources of CPU.

It not only solves the problem of excessive memory consumption and low scheduling efficiency when dealing with a large number of connections, but also makes full use of all the CPU cores. The ability to handle concurrent connections on the same hardware is 10 to 100 times that of Apache.

But Nginx's approach is not without its shortcomings.

When the single-core performance of the server is poor, CMS-based dynamic websites may take a long time to execute a request, and requests from other clients will not be executed immediately. It is more obvious when the number of CPU cores is small and worker threads are insufficient.

Fortunately, the performance of the server is getting stronger and stronger, and there are more and more CPU cores under the leadership of AMD. The shortcomings of Nginx are enough to be made up, and the advantages of high efficiency are becoming more and more obvious.

Comprehensive comparison

The processing power of Apache Nginx is limited by 10-100 times. Will it be blocked by complex tasks? no, it may be relatively difficult to set. Relatively complex communities are relatively rich in resources.

In recent years, the market share of Nginx has been increasing, and it has reached the same level as Apache in 2019. For large websites with a large number of visitors, you can see that the greater the number of visitors, the higher the proportion of Nginx. This also confirms the superior performance of Nginx in handling a large number of visits from the side.

Load balancing

Nginx not only can be used as a HTTP server, its powerful reverse proxy function is also widely used as a load balancing front-end server, gradually replacing the hardware-based load balancer.

Several back-end servers can be configured in Nginx. After receiving the HTTP request, Nginx forwards the request to the back-end server according to certain rules (polling, IP hash, priority random), so as to achieve equal or weighted load distribution among multiple servers.

At the same time, as the front-end of the load balancer, it can also cache the data returned by the back-end to ease the pressure on the back-end server. The front end uses Nginx for load balancing to limit the number of connections per server, and it is not uncommon for back-end servers to run Apache.

F5 networks, the leading hardware load balancer, acquired Nginx in 2019 and launched Nginx+, a load balancing solution that includes paid services.

These are all the contents of this article, "which is better, Apache HTTP or Nginx engine?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

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