Nginx Features
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 the service
The community is active and various high-performance modules are produced quickly
Apache Features
pache'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, has fewer bugs, nginx has relatively more bugs
apache is super stable
apache has relatively simple support for PHP, nginx needs to be used in conjunction with other backends
Apache has an advantage in handling dynamic requests, but nginx is useless in this regard. Generally, dynamic requests have to be handled 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 that apache is a synchronous multi-process model , one connection corresponds to one process, and nginx is asynchronous, multiple connections (10,000 levels) can correspond to one process
Generally speaking, use nginx for web services that require performance. 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 usage 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!