Home  >  Article  >  Backend Development  >  Comparative analysis of PHP server Apache and Nginx

Comparative analysis of PHP server Apache and Nginx

不言
不言forward
2018-10-29 17:04:223236browse

The content of this article is about the comparative analysis of PHP server Apache and Nginx. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Comparison of the advantages and disadvantages of Apache and Nginx

1. Advantages of nginx over apache:

Lightweight, also serves web services, and takes up less memory than apache And resources

Anti-concurrency, nginx processes requests asynchronously 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

Advantages of apache over nginx:

rewrite, more powerful than nginx's rewrite

There are so many modules, you can basically find everything you can think of

Few bugs, nginx has relatively many bugs

Super stable

Existence is the reason, generally For web services that require performance, use nginx. If you don't need performance and just want stability, then use apache. 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 a few file, 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. welcome. 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 virtual host business owners in the United States. It can support responses of up to 50,000 concurrent connections. Thanks to Nginx for 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 adopts Written in C, both system resource overhead and CPU usage efficiency are 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.fm describes a successful and wonderful 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 particularly easy to start, and can run almost 24/7 without needing to be restarted 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’s static processing performance is more than 3 times higher than Apache

Apache’s support for PHP is relatively simple, Nginx needs to be used in conjunction with other backends

Apache It has more components than Nginx

Now Nginx is the first choice for web servers

4. The core difference is that apache is a synchronous multi-process model, and 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 and has many rich features. So it still needs to be matched. .Of course, if it can be determined that nginx meets the needs, then using nginx will be a more economical way.

6. Judging from personal past usage, the load capacity of nginx is much higher than that of apache. The latest server also uses nginx. Moreover, 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 cluster , the cooperation is also good.

7. It is useless for nginx to handle dynamic requests. Generally, apache is required to handle dynamic requests. 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. It has been developed longer than nginx and has fewer bugs. However, apache has the disadvantage of not supporting multi-core processing loads. It is recommended to use nginx as the front end and back end. Use apache. For large websites, it is recommended to use the cluster function of nginx

9. There are two main reasons why Nginx is better than apache: 1. Nginx itself is a reverse proxy server 2. Nginx supports 7-layer load balancing; others, of course, Nginx may support higher concurrency than apache, but according to NetCraft statistics, April 2011 statistics, 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 are already very Decent performance.

10. Your needs for web server determine 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. You can take a look at the nginx lua module: https://github.com/chaoslaw... Apache has more modules than nginx. Apache can be implemented directly with lua. Apache is the most popular. Why? Most people are too lazy to update to nginx or learn new things

12. For nginx, I like that its configuration file is very concise. Regular configuration makes many things simple, has high operating efficiency, takes up less resources, and has proxy functions. Powerful, very suitable for 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

Nginx The advantage is:

  1. works above the 7th layer of the network, and can make some diversion strategies for http applications, such as domain names and directory structures. Its regular rules are more powerful than HAProxy And flexibility is one of the main reasons why it is currently widely popular. Nginx can be used in far more situations than LVS based on this alone.

  2. Nginx has very little dependence on network stability. In theory, it can perform load functions if it can be pinged. This is also one of its advantages; on the contrary, LVS It relies heavily on network stability, which I have a deep understanding of;

  3. Nginx is relatively simple to install and configure, and it is more convenient to test. It can basically print out errors in logs. The configuration and testing of LVS takes a relatively long time, and LVS relies heavily on the network.

  4. It can withstand high load pressure and is stable. If the hardware is not bad, it can generally support tens of thousands of concurrency, and the load degree is relatively smaller than LVS.

  5. Nginx can detect internal server failures through the port, such as status codes, timeouts, etc. returned by the server processing web pages, and will resubmit requests that return errors to another node. , but the disadvantage is that it does not support URL detection. For example, if the user is uploading a file, and the node processing the upload fails during the upload process, Nginx will switch the upload to another server for reprocessing, and LVS will be directly disconnected. If a large file is uploaded, Or very important files, users may be dissatisfied.

  6. Nginx is not only an excellent load balancer/reverse proxy software, it is also a powerful web application server. LNMP is also a very popular web architecture in recent years, and its stability is also very good in high-traffic environments.

  7. Nginx is now becoming more and more mature as a Web reverse acceleration cache and is faster than the traditional Squid server. You can consider using it as a reverse proxy accelerator.

  8. Nginx can be used as a mid-level reverse proxy. At this level, Nginx is basically unmatched. The only one that can compare with Nginx is lighttpd. However, lighttpd has not yet achieved the full performance of Nginx. The functions and configuration are not so clear and easy to read, and the community information is far less active than Nginx.

  9. Nginx can also be used as a static web page and image server, and its performance in this area is unmatched. The Nginx community is also very active and there are many third-party modules.

The disadvantages of Nginx are:

  1. Nginx can only support http, https and Email protocols, so the scope of application is smaller. This is its shortcoming.

  2. The health check of the back-end server only supports detection through ports and does not support detection through URLs. Direct retention of Session is not supported, but it can be solved through ip_hash.

The above is the detailed content of Comparative analysis of PHP server Apache and Nginx. For more information, please follow other related articles on the PHP Chinese website!

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