Home  >  Article  >  Backend Development  >  Advantages and disadvantages of nginx and apache

Advantages and disadvantages of nginx and apache

WBOY
WBOYOriginal
2016-08-08 09:24:071002browse

Content of this section:
Advantages and disadvantages of nginx and apache

1. Advantages of nginx over apache:
Lightweight, can also serve as a web service, and takes up less memory and resources than the apache server
Anti-concurrency, nginx is processing The request is asynchronous and non-blocking, while apache is blocking. Under high concurrency, nginx can maintain low resources, low consumption and high performance.
Highly modular design, writing modules is relatively simple.
The community is active and various high-performance modules are produced quickly. Ah
The advantages of apache over nginx:
rewrite, more powerful than nginx's rewrite
Dynamic pages
There are so many modules, you can basically find everything you can think of
Fewer bugs, nginx has relatively many bugs
Super stable

The reason for existence, Generally speaking, for web services that require performance, use nginx. If you don't need performance and just want stability, then use apache. The various functional modules of the latter are implemented better than the former. For example, the ssl module is better than the former and has more configurable items. One thing to note here is that 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 With just a few 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. The real application still needs to be tested in practice.

2. As a Web server: Compared with Apache, Nginx uses fewer resources, supports more concurrent connections, and reflects higher efficiency. This makes Nginx especially popular with virtual host providers. In the case of high connection concurrency, Nginx is a good alternative to the Apache server: Nginx is one of the software platforms often chosen by bosses in the virtual host business in the United States. It can support responses of up to 50,000 concurrent connections, thanks to Nginx We chose epoll and kqueue as the development model.

Nginx as the load balancing server: Nginx can not only directly support Rails and PHP programs to serve externally internally, but also support external services as an HTTP proxy server. Nginx is written in C , both in terms of system resource overhead and CPU usage efficiency, it is much better than Perlbal.

As a mail proxy server: Nginx is also a very excellent mail proxy server (one of the earliest purposes of developing this product is also as a mail proxy server), Last Last .fm describes a successful and wonderful usage experience.
Nginx is a server that is very simple to install, has a very concise configuration file (it can also support perl syntax), and has very few bugs: Nginx is very easy to start, and almost can be done 7*24 uninterrupted operation, no need to restart even if it runs for several months. You can also upgrade the software version without interrupting the service.

3. Nginx configuration is simple, Apache is complex
Nginx static processing performance ratio Apache is more than 3 times higher
Apache’s support for PHP is relatively simple, Nginx needs to be used with other backends
Apache has more components than Nginx
Now Nginx is the first choice for web servers

Four. The core difference is that apache is a synchronous multi-process Model, one connection corresponds to one process; nginx is asynchronous, multiple connections (10,000 levels) can correspond to one process


5. nginx handles static files well and consumes less memory. But there is no doubt that apache is still the mainstream at present, with many rich features Features. Therefore, they need to be matched. Of course, if it is determined that nginx suits the needs, then using nginx will be a more economical way.
apache has the disadvantage of not supporting multi-core processing loads, so it is recommended to use nginx as the front end. The backend uses apache. Large websites are recommended to use the cluster function of nginx. 6. Judging from personal past usage, the load capacity of nginx is much higher than that of apache. The latest server also uses nginx. And after changing the configuration of nginx, you can -t test whether there is any problem with the configuration. When apache restarts, it is found that the configuration is wrong and it will crash. I will be very careful when making changes. Now there are many cluster sites. The front-end nginx is anti-concurrency, and the back-end apache The cluster works well together.

7. It is useless for nginx to handle dynamic requests. Generally, apache is required to handle dynamic requests, and nginx is only suitable for static and reverse requests.

8. From my personal experience, nginx is a very good front-end server with very good load performance. It is effortless to open nginx on Laoben and use webbench to simulate 10,000 static file requests. Apache has good support for languages ​​​​such as php

. In addition, apache has a strong support network and has been developed longer than nginx.


9. Nginx is superior to apache in two main points: 1. Nginx itself is a reverse proxy server 2. Nginx supports 7-layer load balancing; of course, Nginx may support higher concurrency than apache, but according to statistics from NetCraft
, in April 2011, Apache still accounts for 62.71%, while Nginx is 7.35% , so in general, Aapche is still the first choice for most companies, because its mature technology and development community have very good performance.

10. The demand for web server determines your choice. In most cases, nginx is better than APACHE, such as static file processing, PHP-CGI support, reverse proxy function, front-end Cache, connection maintenance, etc. In
Apache+PHP (prefork) mode, if PHP processing is slow or the front-end pressure is high, it is easy for the number of Apache processes to surge, resulting in a denial of service.

11. nginx lua module: Apache can be implemented directly using lua, which is the most popular.

12. For nginx, the configuration file is written very concisely. Regular configuration makes many things simple and efficient. It takes up less resources and has powerful proxy functions. It is very suitable for being a front-end response server.

13. Apache has advantages in processing dynamics. Nginx has better concurrency and low CPU memory usage. If rewrite is frequent, then Apache is the best choice.

The above has introduced the advantages and disadvantages of nginx and apache, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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