Apache vs nginx

From WikiVS, the open comparison website
Jump to: navigation, search
Apache Nginx
Apache
VS
Nginx
http://httpd.apache.org http://nginx.org

Both Apache and nginx (pronounced “engine-x”) are free, open-source, cross-platform web servers.

The Apache HTTP Server, commonly referred to as Apache, is a web server notable for playing a key role in the initial growth of the World Wide Web. [...] In 2009 Apache became the first web server to surpass the 100 million web site milestone. [...] Since April 1996 Apache has been the most popular HTTP server on the World Wide Web. As of March 2009, Apache served over 46% of all websites and over 66% of the million busiest.

nginx is noted to be a good server for sites that need fast, efficient reverse proxies [1], [2], [3] or fast, efficient serving of static content [4]. It is acclaimed for having low memory usage and is recommended for sites running on a VPS[5].

Apache is like Microsoft Word, it has a million options but you only need six. Nginx does those six things, and it does five of them 50 times faster than Apache.

Contents

[edit] Architecture

Apache is a process-based server, while nginx is an event-based web server.

Nginx and Lighttpd are probably the two best-known asynchronous servers and Apache is undoubtedly the best known process-based server. [...] The main advantage of the asynchronous approach is scalability. In a process-based server, each simultaneous connection requires a thread which incurs significant overhead. An asynchronous server, on the other hand, is event-driven and handles requests in a single (or at least, very few) threads.

While a process-based server can often perform on par with an asynchronous server under light loads, under heavier loads they usually consume far more RAM which significantly degrades performance. Also, they degrade much faster on less powerful hardware or in a resource-restricted environment such as a VPS.

Pulling numbers from thin air for illustrative purposes, serving 10,000 simultaneous connections would probably only cause Nginx to use a few megabytes of RAM whereas Apache would probably consume hundreds of megabytes (if it could do it at all).

[edit] Features

Like Apache, Nginx has all the features you would expect from a leading Web server:

  • Static file serving.
  • SSL/TLS support.
  • Virtual hosts.
  • Reverse proxying.
  • Load balancing.
  • Compression.
  • Access controls.
  • URL rewriting.
  • Custom logging.
  • Server-side includes.
  • Limited WebDAV.
  • FLV streaming.
  • FastCGI.

It is stable, secure and very easy to configure, as you will see later in the article. However, the main advantages of Nginx over Apache are performance and efficiency. [...] Whether you are looking to get the most out of your VPS or are attempting to scale one of the largest Web sites in the world, Nginx may be the best tool for the job. It's fast, stable and easy to use.

According to the Wikipedia article "Comparison of web servers", Apache has the following extra features compared to nginx:

  • digest access authentication
  • CGI
  • administrative console
  • .htaccess


I mentioned earlier that nginx isn’t very suited for shared hosting. You might think that if you let nginx handle just static files while proxying non-existing files and dynamic files to Apache then you’ll be good. This isn’t quite the case, though. As an example, consider basic authentication, if you want to have basic authentication on a static file then you will need to add it in the nginx configuration, and users cannot do this without having to reload the configuration file. If you allow them to change it and reload it then they can make a mistake and ruin it for everyone.

[6]

[edit] Performance

nginx is faster at serving static files and consumes much less memory for concurrent requests because Nginx is event-based it doesn't need to spawn new processes or threads for each request, so its memory usage is very low

Wordpress.com has found nginx to be the only load balancer able to handle 8000 live traffic requests per second.[7]

The only solution I know of that's extremely high performance that offers all of the features that you want is nginx [...] I currently have nginx doing reverse proxy of over tens of millions of HTTP requests per day (thats a few hundred per second) on a *single server*. At peak load it uses about 15MB RAM and 10% CPU on my particular configuration (FreeBSD 6).

Under the same kind of load, apache falls over (after using 1000 or so processes and god knows how much RAM), pound falls over (too many threads, and using 400MB+ of RAM for all the thread stacks), and lighty *leaks* more than 20MB per hour (and uses more CPU, but not significantly more).

[edit] Ease of use

Configuration Tools [of nginx] is a cinch and deployment was easy as pie.

[nginx] is stable, secure and very easy to configure, as you will see later in the article.

Nginx: the High-Performance Web Server and Reverse ProxyLinux Journal, September 2008

We were using Pound for load balancing at Justin.tv until today. It was consistently using about 20% CPU, and during spikes would use up to 80% CPU. Under extremely high load, it would occasionally freak out and break.

We just switched to Ngnix, and load immediately dropped to around 3% CPU. Our pages feel a little snappier, although that might be my imagination. Not only is the config format easier to understand and better documented, but it offers a full webserver's complement of functionality.

[edit] Popularity

In 2009 Apache became the first web server to surpass the 100 million web site milestone. [...] Since April 1996 Apache has been the most popular HTTP server on the World Wide Web. As of March 2009, Apache served over 46% of all websites and over 66% of the million busiest.

Apache's web server market share is increasing again since early 2010, and Nginx has been more or less stable for a while now (since late 2009), according to Netcraft web server surveys for July 2011.

[edit] Licensing

nginx is distributed under the terms of the Simplified BSD License, a two-clause, copyfree variant of the BSD License. This licensing choice significantly reduces collaborative friction between nginx code and that of other projects distributed under other licenses, and imposes no notable restrictions on software development related to nginx.

Apache uses the eponymous Apache License 2.0, a license sometimes considered "permissive" in that it is an open source license that is not a copyleft license. It still applies restrictions on software modification and distribution above and beyond that of copyfree licenses such as the Simplified BSD License used by nginx, however. The differences include change notification bookkeeping for modified files, as well as substantially more complex license text. A potential benefit of the Apache License 2.0 over the Simplified BSD License is the Apache License's patent clause, though the utility of such a clause may be debatable.

[edit] External Links

See Also the Following Articles

Personal tools
Namespaces
Variants
Actions
Navigation
Ads
Toolbox