search
HomeOperation and MaintenanceNginxWhich engine is better, Apache HTTP or Nginx?

Which engine is better, Apache HTTP or Nginx?

May 11, 2023 pm 03:49 PM
httpapachenginx

HTTP middleware

When we enter a web link in the browser, the browser sends a request to the corresponding server based on the HTTP(s) transmission protocol, and the server receives The corresponding request is processed and the corresponding information is returned to the browser. The browser then parses the content in 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 processes 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)

Regardless of what kind of application the application part executes, it is the part that handles the http connection They are almost the same, so middleware has emerged that specifically handles http connections. Currently, the most common ones are Apache and Nginx.

Apache

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

Apache's internal processing model

In terms of internal structure, Apache adopts a multi-process approach. Each time there is a connection, a process will be opened for this connection, specifically for Handle requests on this connection until the connection ends. The advantage of this is:

  • Connections from different clients will be responded immediately without interfering with each other, and other connections will not be affected because one service takes a long time. No response.

But the shortcomings are also obvious:

  • When there are many simultaneous accesses, Apache will create a large number of Process, occupying too much memory resources.

  • Scheduling between a large number of threads will also cause a lot of waste of CPU processing power.

This gave rise to a problem called C10K, C is the client, and 10K refers to 10,000, regardless of the performance of the server and the network No matter how high the bandwidth is, it will be difficult for Apache to handle more than 10,000 connections at the same time.

Nginx

is pronounced as Engine-X, and like Apache, it is also an open source middleware for HTTP service, born in 2004. Nginx has a shorter history than Apache, but precisely because it is a latecomer, Nginx learned the lessons of Apache and implemented it in the early design stage. Taking into account the efficiency issue when handling a large number of connections, it solves the problems that arise with the growth of the Internet, such as C10K.

Nginx’s internal processing model

Nginx adopts non-blocking IO and asynchronous message-driven methods, which is called worker uses a loop in the thread to process the connection request in the queue. Depending on the hardware, multiple worker threads can be set to make full use of CPU's core resources.

  • It solves the problem of excessive memory consumption and low scheduling efficiency when processing a large number of connections, and at the same time, it can fully utilize all CPU cores. The ability to handle concurrent connections on the same hardware is 10 to 100 times that of Apache.

ButNginxThis method is not without its shortcomings.

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

Fortunately, the performance of servers is getting stronger and stronger. Under the leadership of AMD, the number of CPU cores is also increasing,# The shortcomings of ##Nginx are enough to be compensated, and the advantages of high efficiency are becoming more and more apparent.

Comprehensive comparison

Apache NginxThe processing capacity is limited 10-100 times. Will it be blocked by complex tasks? Is it possible to set the difficulty to be relatively simple and relatively complex? The community has rich resources and relatively Less

In recent years, the market share of

Nginx has continued to increase, and in 2019 it has reached the same level as Apache. For large websites with a huge number of visits, you can see that the greater the number of visits, the higher the proportion of Nginx will be. This also confirms the superior performance of Nginx when handling a large number of accesses.

Load Balancing

NginxIn addition to being used as an HTTP server, its powerful reverse proxy function is also widely used as a load balancing front-end server, gradually replacing the Hardware load balancer.

Several backend servers can be configured in

Nginx. Nginx will follow certain rules (polling, IP Hash, priority random), etc. forward the request to the back-end server to achieve average or weighted distribution of load on multiple servers.

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

The industry leader of hardware load balancersF5 networks acquired Nginx in 2019 and launched a load balancing solution including paid servicesNginx .

The above is the detailed content of Which engine is better, Apache HTTP or Nginx?. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
The Ultimate Showdown: NGINX vs. ApacheThe Ultimate Showdown: NGINX vs. ApacheApr 18, 2025 am 12:02 AM

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX in Action: Examples and Real-World ApplicationsNGINX in Action: Examples and Real-World ApplicationsApr 17, 2025 am 12:18 AM

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINX Unit: Supporting Different Programming LanguagesNGINX Unit: Supporting Different Programming LanguagesApr 16, 2025 am 12:15 AM

NGINXUnit supports multiple programming languages ​​and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.

Choosing Between NGINX and Apache: The Right Fit for Your NeedsChoosing Between NGINX and Apache: The Right Fit for Your NeedsApr 15, 2025 am 12:04 AM

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

How to start nginxHow to start nginxApr 14, 2025 pm 01:06 PM

Question: How to start Nginx? Answer: Install Nginx Startup Nginx Verification Nginx Is Nginx Started Explore other startup options Automatically start Nginx

How to check whether nginx is startedHow to check whether nginx is startedApr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to close nginxHow to close nginxApr 14, 2025 pm 01:00 PM

To shut down the Nginx service, follow these steps: Determine the installation type: Red Hat/CentOS (systemctl status nginx) or Debian/Ubuntu (service nginx status) Stop the service: Red Hat/CentOS (systemctl stop nginx) or Debian/Ubuntu (service nginx stop) Disable automatic startup (optional): Red Hat/CentOS (systemctl disabled nginx) or Debian/Ubuntu (syst

How to configure nginx in WindowsHow to configure nginx in WindowsApr 14, 2025 pm 12:57 PM

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor