Home  >  Article  >  Operation and Maintenance  >  What are the characteristics and differences between Nginx and Apache

What are the characteristics and differences between Nginx and Apache

王林
王林forward
2023-05-13 20:10:141189browse

1. Nginx features

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

2. Anti-concurrency, nginx uses epollandkqueue 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.

3. When nginx is started, it will generate a master process. Then, the master process will fork multiple worker sub-processes. Finally, each user's request is processed by the worker's sub-thread.

4. You can configure nginx’s upstream to implement nginx’s reverse proxy.

5. As a load balancing server, nginx supports layer 7 load balancing.

6. nginx handles static files well, and its static processing performance is more than three times higher than apache.

7. Supports high concurrent connections. The maximum number of concurrent connection requests per second can theoretically reach 50,000.

8. The nginx configuration is simple. Regular configuration makes many things simple. After changing the configuration, you can use -t to test whether there are any problems with the configuration. The apache configuration is complex. When you restart, you will find that the configuration is wrong and it will crash. .

9. Use threads to process user requests, and threads share memory. You only need to open a small number of processes, and multiple threads can share the memory of the process and occupy a small amount of memory.

10. When a process dies, it will affect the use of multiple users and cause poor stability.

11. The design of nginx is highly modular, and writing modules is relatively simple.

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

13. 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. It can also upgrade the software version without interrupting the service.

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

2. Apache features

1. Select synchronization blocking.

2. One connection corresponds to one process.

3. Use a process to handle user requests, use MPM (multi-processing module) to bind to the network port, accept the request, and schedule sub-processes to handle the request.

4. When there are too many user requests, there will be many processes opened and a large amount of memory occupied. The maximum number of concurrent connection requests per second shall not exceed 3,000.

5. When a process dies, it will not affect other users.

6. Apache's rewrite is more powerful than nginx. If rewrite is frequent, use apache.

7. With the development of apache, there are so many modules that you can basically find everything you can think of.

8. Apache is more mature and has fewer bugs, while nginx has relatively more bugs.

9. Apache is super stable.

10. Apache’s support for PHP is relatively simple, and nginx needs to be used with other backends.

11. Apache has advantages in handling dynamic requests. Generally, dynamic requests need to be done by apache, while nginx is suitable for static and reverse.

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

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, and 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. Apache’s various functional modules are better than nginx. For example, the ssl module is better than nginx 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, only a few Several files, apache's select model may be more performant than epoll.

Of course, this is just an assumption based on the principles of the network IO model. Real applications still require actual testing.

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

The above is the detailed content of What are the characteristics and differences between Nginx and Apache. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete