Home>Article>Backend Development> What is the difference between PHP server nginx and apache

What is the difference between PHP server nginx and apache

青灯夜游
青灯夜游 Original
2022-08-11 17:08:58 3234browse

Difference: 1. Apache is a synchronous multi-process model, one connection corresponds to one process, while nginx is asynchronous, multiple connections can correspond to one process, and nginx has a higher load capacity than apache; 2. apache is suitable for processing Dynamic requests, while nginx is suitable for handling static and reverse; 3. nginx configuration is simple, while apache configuration is complex; 4. apache's rewrite is more powerful than nginx; 5. apache is more mature and has fewer bugs, while nginx has relatively more bugs.

What is the difference between PHP server nginx and apache

The operating environment of this tutorial: windows7 system, PHP8.1 version, DELL G3 computer

Nginx

  • Lightweight, written in C, the same web service will occupy less memory and resources

  • Anti-concurrency, nginx uses epoll and As a development model, kqueue handles requests asynchronously and non-blockingly, and its load capacity is much higher than that of apache, while apache is blocking. Under high concurrency, nginx can maintain low resource consumption and high performance, while apache is prone to a surge in the number of processes and denial of service when PHP processing is slow or the front-end pressure is high.

  • nginx handles static files well, and the static processing performance is more than three times higher than apache

  • nginx’s design is highly modular, and writing modules is relatively simple

  • nginx configuration is simple, regular configuration makes many things simple, and after changing the configuration, you can use -t to test whether there are any problems with the configuration. Apache configuration is complex, and when restarting, it is found that the configuration is wrong. It will crash

  • nginx, as a load balancing server, supports 7-layer load balancing

  • nginx itself is a reverse proxy server and can be used as A very excellent mail proxy server

  • It is very easy to start and can run almost 24/7 without interruption. Even if it runs for several months, it does not need to be restarted and it can provide uninterrupted service. Upgrade the software version under certain circumstances

  • The community is active and various high-performance modules are produced quickly

Apache

  • apache's rewrite is more powerful than nginx. When rewrite is frequent, use apache

  • apache has developed so far, there are so many modules, basically think of it You can find them all

  • apache is more mature and has fewer bugs, while nginx has relatively more bugs

  • apache is super stable

  • apache's support for PHP is relatively simple, nginx needs to be used in conjunction with other backends

  • apache has advantages in handling dynamic requests, nginx is useless in this regard, general dynamic The request needs to be done by apache, and nginx is suitable for static and reverse.

  • apache is still the current mainstream, with rich features, mature technology and development community

Summary

The core difference between the two is that apache is a synchronous multi-process model, one connection corresponds to one process, while nginx is asynchronous, multiple connections (10,000 levels) can correspond to one process

Generally speaking Say, for web services that require performance, use nginx. If you don't need performance and just want stability, consider apache. The latter's various functional modules are better implemented than the former. For example, the ssl module is better than the former and has more configurable items. The epoll (kqueue on freebsd) network IO model is the fundamental reason for nginx's high processing performance, but epoll does not win in all cases. If it provides static services, there are only a few files, and apache's The select model may be more performant than epoll. Of course, this is just an assumption based on the principles of the network IO model. The real application still needs to be tested in practice.

Since nginx is faster than apache, why does nginx not replace apache?

  • Because the two things have different focuses, Apache itself has many built-in things and can support almost all Web-type applications without the help of other things. Nginx is different. It has advantages in static file processing and high concurrency.

  • Apache focuses on completeness and stability, while Nginx focuses on lightweight and high efficiency. In many cases, Apache and Nginx are used together. Nginx is configured in front of Apache and is used to block static files. requests (the website's resource requests account for the majority today), content dishes that Nginx cannot handle are forwarded to Apache for processing.

Should we choose Nginx or Apache?

  • apache is better for running php and is suitable for running dynamic

  • nginx is more suitable for running static.

  • The popular lanmp architecture now uses apache and nginx at the same time. Static web pages are processed by nginx, and dynamic web pages are processed by apache, so that server performance can be maximized.

  • The general solution is that the front-end nginx is anti-concurrency and the back-end apache cluster works better together.

For more programming-related knowledge, please visit:Programming Video! !

The above is the detailed content of What is the difference between PHP server nginx and apache. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn