Which engine is better, Apache HTTP or Nginx?
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
.
ButNginx
This 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 andworker
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.
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
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.
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.
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

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.

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

To get Nginx to run Apache, you need to: 1. Install Nginx and Apache; 2. Configure the Nginx agent; 3. Start Nginx and Apache; 4. Test the configuration to ensure that you can see Apache content after accessing the domain name. In addition, you need to pay attention to other matters such as port number matching, virtual host configuration, and SSL/TLS settings.

Steps to create a Docker image: Write a Dockerfile that contains the build instructions. Build the image in the terminal, using the docker build command. Tag the image and assign names and tags using the docker tag command.

There are many ways to solve CentOS system failures. Here are some common steps and techniques: 1. Check the log file /var/log/messages: system log, which contains various system events. /var/log/secure: Security-related logs, such as SSH login attempts. /var/log/httpd/error_log: If you use the Apache server, there will be an error message here. 2. Use the diagnostic tool dmesg: display the contents of the kernel ring buffer, which helps understand hardware and driver questions
