Comparison and merit-based Web servers-Apache, nnginx, and Lighttpd

Source: Internet
Author: User
Advantages and disadvantages of Apache server and nginx: 

We used Apache in large numbers as httpserver. Apache has excellent performance and provides a variety of functions through modules.


  1. First, Apache supports concurrent responses to the client.After running the httpd daemon process, it will generate multiple child processes/threads at the same time, and each child process/thread will respond to the client requests separately;
  2. In addition, Apache can provide static and dynamic services.For example, PHP Parsing is implemented through a module that supports PHP rather than a cgi with poor performance (usually mod_php5 or apxs2 ).


  1. Apache serverProcess-based Server, That is, the multi-process-based httpserver, because it needs to create a child process/thread for each user request to respond; the disadvantage is that, if there are a lot of concurrent requests (which is common in large portal websites), a lot of threads are required to occupy a lot of CPU and memory resources.Therefore, concurrent processing is not an Apache strength.


  • At present, another kind of webserver has emerged, which is superior in terms of concurrency, called asynchronous servers Asynchronous Server. The most famous ones are nginx and Lighttpd. The so-called Asynchronous Server is the event-driven in the event-driven mode. In addition to the user's concurrent requests, only one or several threads are required. Therefore, system resources are very small. These are also called lightweight Web servers.

For example, for 10,000 concurrent connection requests, nginx may only use a few MB of memory, while Apache may need several hundred MB of memory resources.

Single Use in reality

1) We do not need to introduce the single use of Apache as an httpserver, which is a very common application;

As mentioned above, Apache's support for PHP and other server scripts is achieved through its own modules, and the performance is superior.


2) We can also use nginx or Lighttpd as httpserver alone.

Similar to nginx, Lighttpd, and Apache, you can use various modules to expand the functions of the server. You can also configure various options through the conf configuration file.

For PHP, nginx and Lighttpd do not have built-in modules to support PHP, but FastCGI.

Lighttpd provides CGI, FastCGI, scgi, and other services through the module. nginx does not provide its own function for processing PHP. It must use a third-party module to provide FastCGI integration for PHP.


Lighttpd vs nginx: Http://



Reverse Proxy reverse proxy 

1) proxy server concept Proxy Server: 

Proxy Server
The concept is easy to understand. It is usually used as a machine between two machines. The features that need to be provided often include:

  1. Cache caching,
  2. Security,
  3. Load balancing.

The so-called load balancing means that when many machines use a proxy, the proxy server needs to balance each server.

Our common proxy isForward proxyFor example, if we have 20 computers in the data center to access the Internet and only one computer can access the Internet, we can use this computer as the proxy server. All data transmitted over the network must go through this proxy server.
Reverse Proxy is opposite to forward proxy.For service recipient users, the reverse proxy or server proxy is for the server, meaning there are multiple servers, the reverse proxy server sends a user's request proxy to one of the servers for processing.

Proxy Server: Http://


2)In reality, for a large website, we usually use many severs to form a cluster to respond to various user requests. ThereforeOne or more reverse proxy servers are usually required to serve multiple servers. 

The reverse proxy server generally provides the following functions:

  1. Security;
  2. Cache compression function;
  3. Load Balancing function;

Reverse Proxy: Http://

(The reverse proxy server and the firewall have similar advantages, but the firewall generally only has security considerations and has no caching and load balancing functions .)


3) In summary, the actual Web Server Architecture 
Generally, multiple Web servers run concurrently to provide services;

At the same time, one or more reverse proxy servers need to be deployed in the front of the Web server. On the one hand, some static data is cached, or some content dynamically generated by the Web server is cached. On the other hand, the load balancing function is used, the user's concurrent requests can be evenly transmitted to multiple Web servers for processing.

In this way, the load on each web server can be greatly reduced, and load balancing on multiple servers can be achieved on the other side.


Nginx/Lighttpd as the reverse proxy server

Nginx or Lighttpd acts as a reverse proxy server on the front end, and multiple apachehttpservers are arranged in the background: 

  • As mentioned above, nginx and Lighttpd have the advantages of fast and lightweight, and are much better than Apache servers in terms of processing multi-user concurrency. 

Therefore, we can usually place them as reverse proxy servers in front of Multiple Apache Web servers to cache data and achieve load balancing among multiple servers.

  • Of course, Apache can also implement reverse proxy and cache functions through mod_proxy and mod_cache.But it cannot be compared with servers in simple asynchronous mode such as nginx and Lighttpd in terms of processing high concurrency.
  • In addition, by using the response proxy functions of nginx and Lighttpd, we can set the configuration file, when the client requests static content (such as some images, JS, HTML files, etc, directly responds to nginx or Lighttpd;
  • If you need to access dynamic content (which usually needs to be read from the database in real time), you can send the request to the backend Apache for response through reverse proxy or nginx, apache then returns the result to nginx, which can be cached when responding to the user.
  • Sometimes some caching tools, such as squid, can be used.In addition, nginx also provides support for some caching functions, suchMemcache.

Therefore, if we analyze the image,Nginx is the frontend Web Cache System,The general architecture is as follows:

Advantages of this structure:

  1. You can use the nginx front-end to perform a lot of complex configurations. These configurations were previously not feasible or difficult to do in Squid, such as anti-leech targeting directories.
  2. The nginx front-end can directly forward some requests that do not need to be cached.
  3. Because nginx is more efficient than squid, you can use nginx cache to reduce squid pressure in some cases.
  4. URL hash and other allocation policies can be implemented
  5. You can enable gzip compression at the frontend, so that the Squid cache is purely non-compressed documents, which can avoid unnecessary penetration.
  6. Because nginx has high stability, LVS does not need to be adjusted frequently. you can adjust it through nginx.
  7. The number of squid files opened is more than 1024 by default, but there are no fewer requests to process.
  8. You can enable the nginx log function to replace squid. In this way, the URL can be precisely located during real-time click statistics, and inefficient grep is not necessary to be used for filtering.
  9. Because the load capacity of nginx is higher than squid, you do not need to be balanced when using LVS for traffic distribution, and the probability of single point of failure is relatively low.


Front-end system architecture of web servers built with nginx and squid:

The front-end LVS and squid, according to the installation method, open epoll, copy the configuration file, basically there are not many problems.

The difference between this architecture and the app_squid architecture is also the key point: when a level-1 middle-level proxy is added, there are too many advantages for the middle-level proxy:

  1. Gzip compression: compression can be performed through nginx. In this way, backend application servers, whether Apache, resin, Lighttpd, or IIS or other odd servers, do not need to consider the compression function.
  2. Server Load balancer and fault shielding: nginx can be used as a server Load balancer proxy and has a fault shielding function. In this way, the Server Load balancer policy based on the directory or even a regular expression becomes a small case.
  3. Convenient O & M management allows you to flexibly develop solutions in various situations.
  4. Clear permissions: maintenance personnel who do not write programs are responsible for this machine. Programmers generally do not need to manage this machine. In this way, if a fault occurs, it is easy to find the right person. For application servers and database servers, it is best to disappear from the eyes of the maintenance personnel. My goal is that as long as these services can run, all other tasks can be handled externally.




Nginx as the frontend Web Cache System:

Web Server front-end system built with nginx and squid:

General architecture of LVS clusters:




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.