Nginx details reverse proxy, load balancing, LNMP architecture online dynamic website

Introducing nginx

13

13 span style=”color: #000000;”> Nginx is a very lightweight HTTP server written by Russians, Nginx, which is pronounced “engine X” is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server. Nginx was developed by Russian Igor Sysoev for the second most visited Rambler.ru site in Russia, and it has been running on the site for more than two and a half years. Igor Sysoev used a BSD-based license when building the project.

nginx and apache difference

Nginx

  1. Lightweight, written in C, the same web service will take up more Less memory and resources
  2. anti-concurrency, nginx uses epoll and kqueue as the development model, processing requests is asynchronous and non-blocking, load The ability is much higher than apache, and apache is blocking. Under high concurrency, nginx can maintain low resources, low consumption and high performance, while apache is prone to soaring number of processes and denial of service when PHP processing is slow or front-end pressure is high.
  3. nginx handles static files well, and static processing performance is more than three times higher than that of apache
  4. < span style="font-family: 宋体;">nginx’s design is highly modular, and writing modules is relatively simple
  5. nginx configuration is simple , Regular configuration makes a lot of things simple, and after changing the configuration, you can use -t to test whether there is any problem with the configuration. The apache configuration is complicated. When you restart it, you find that the configuration is wrong and it will crash
  6. nginx as a load balancing server supports 7-layer load balancing
  7. nginx itself It is a reverse proxy server, and can be used as a very good mail proxy server
  8. Startup is particularly easy, and it can almost do 7 *24 Uninterrupted operation, even if it has been running for several months, it does not need to be restarted, and the software version can be upgraded without interruption of service
  9. The community is active, and various high-performance modules are produced quickly

apache ff 600 style

Apache Pan style=”font-size: 18px;”> >

  1. apache’s rewrite is more powerful than nginx. In the case of frequent rewrites, use apache
  2. apache has developed to the present , There are so many modules, you can find everything you can think of
  3. apache is more mature and has fewer bugs, nginx has relatively more bugs< /span>
  4. apache super stable
  5. Apache’s support for PHP is relatively simple, nginx needs to be used with other backends
  6. apache has advantages in handling dynamic requests, nginx in this respect It is tasteless, generally dynamic requests need to be done by apache, nginx is suitable for static and reverse.

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

< span style="color: #ff6600;">Summary

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, multiple connections (ten thousand 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 than the former. For example, the ssl module is better than the former and has more configurable items. epoll (kqueue on freebsd) The network IO model is the fundamental reason for the high processing performance of nginx, but not in all cases, epoll is a big success. If it provides static services, there are only a few files. Apache’s The select model may have higher performance than epoll. Of course, this is just a hypothesis based on the principle of the network IO model. The real application still needs to be measured.

The more general solution is that the front-end nginx resists concurrency and the back It will be better to cooperate with the apache cluster.

Leave a Comment

Your email address will not be published.