Home  >  Article  >  Operation and Maintenance  >  The difference between nginx and apache

The difference between nginx and apache

步履不停
步履不停Original
2019-06-22 10:31:503978browse

The difference between nginx and apache

Nginx

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

Anti-concurrency, nginx uses epoll and kqueue as the development model, processing requests is asynchronous and non-blocking, and the load capacity is much higher than 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, and regular configuration makes Many things have become simpler, and after changing the configuration, you can use -t to test whether there are any problems with the configuration. The apache configuration is complex. If you find that the configuration is wrong when restarting, it will crash

nginx is a load balancing server and supports 7 layers. Load balancing

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

It is particularly easy to start, and can run almost 7*24 without interruption, even if it is running There is no need to restart for several months, and the software version can be upgraded without interrupting service

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, you can basically find everything you can think of

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 cooperate with other backends

apache It has advantages in handling dynamic requests, but nginx is useless in this regard. Generally, dynamic requests need to be done by apache, and nginx is suitable for static and reverse.

Apache is still the mainstream, with rich features, mature technology and development community

Summary

The core difference between the two is 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, 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.

A more general solution is to use nginx on the front end to resist concurrency and the apache cluster on the back end, which will work better together.

For more Nginx related technical articles, please visit the Nginx Tutorial column to learn!

The above is the detailed content of The difference between 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