Home (Http://Www.hostingadvice.com) > How-To (Http://Www.hostingadvice.com/How-To/)
1,626 (https://www.facebook.com/HostingAdviceCom) 835 (https://twitter.com/Hosting_Advice) 267
(https://plus.google.com/+Hostingadvice/)
Our experts take readers step-by-step through a variety of hosting and programming tasks in our popular series of "How-To" guides.
$ 4 8,2 8 3
spent annually on web hosting services! (http://www.hostingadvice.com/about/)
TL; DR: We assess two of the most popular web servers: NGINX and Apache, on six key points of comparison (performance for static vs. dynamic content, OS support, security, flexibility, documentation, and support). We’ll find that the two are worthy competitors, but Apache’s .htaccess file makes it particularly appealing to shared hosting customers. Meanwhile, NGINX reigns supreme for dynamic content support, and due in part to its more advanced feature offerings, is most popularly used by VPS and dedicated hosting users. Finally, we’ll go over our recommendations for hosting your next web app project.
There was a time (~late 90s-2011) when the Apache web server served around 60 percent — and at times even more — of the world’s websites. That percentage has since fallen below 35 and is still dropping at quite a significant rate (http://news.netcraft.com/archives/2016/01/26/january-2016web-server-survey.html). Meanwhile, Microsoft’s IIS web server has held a somewhat steady, slightly increasing, share of the market, reaching 30 percent today. Third place is held by a competitor called NGINX (pronounced “engine-x”), which currently serves around 16 percent of all sites, and that rate is steadily growing by about one percent each year. I’ll note that some web surveyors place the market shares of Apache and NGINX much higher (http://w3techs.com/technologies/overview/web_server/all), considering IIS a lesser competitor. Reality likely resides somewhere in the middle, but the overall trends are clear. Considering only the busiest sites on the Web, Apache holds about 46 percent of the market share, but that portion
eStruxture's Datacenters Provide On-Demand Capacity and Flexibility (http://www.hostingadvice.com/blog/estruxture(http://www.hostingadvice.com/blog/estruxturedatacenters-power-mission-criticaldatacenters-power-mission-criticalapplications-across-canada/) applications-across-canada/) Laura Bernheim, 3/30/18
(http://www.hostingadvice.com/blog/savviuscontinues-to-innovate-applicationperformance-management-solutions/)
Savvius: Innovating Application Performance Management Solutions (http://www.hostingadvice.com/blog/savviuscontinues-to-innovate-applicationperformance-management-solutions/) Christine Preusler, 3/29/18
Backblaze's Low-Cost, High-Performance B2 Cloud Storage Shines (http://www.hostingadvice.com/blog/backblaze(http://www.hostingadvice.com/blog/backblazebrings-clarity-to-the-cloud-with-b2-cloudbrings-clarity-to-the-cloud-with-b2-cloudstorage/) storage/) Jennifer Young, 3/26/18 more blog posts (http://www.hostingadvice.com/blog/) »
drops by about four percent annually; NGINX holds a strong second place with 24 percent of the market share and is growing at a rate of about three percent each year. Clearly NGINX is enticing the world’s biggest web properties with something! Best Web Hosting 2018 (http://www.hostingadvice.com/reviews/) Cheap Web Hosting (http://www.hostingadvice.com/reviews/cheap/) Dedicated Server Hosting (http://www.hostingadvice.com/reviews/dedicated/) VPS Hosting (http://www.hostingadvice.com/reviews/vps/) WordPress Hosting (http://www.hostingadvice.com/reviews/wordpress/) NetCraft’s Web Server Market Share Comparison: Across All Sites (Left) & Across Top Billion Busiest Sites (Right)
Website Builder (http://www.hostingadvice.com/reviews/websitebuilder/)
In this article, we’ll make NGINX/Apache comparisons for the following areas of interest: Performance
Flexibility
OS Support
Docs
Security
User Support
How Does JustHost Compare With the Top WordPress Hosts? (http://www.hostingadvice.com/howto/justhost-wordpress-review/) Laura Bernheim, 3/26/18
First, let’s make sure we’re all familiar with the web servers we’re comparing… Or you can skip to our summary review of Apache and NGINX, which includes our hosting recommendations (http://www.hostingadvice.com/reviews/linux/).
Looking for Anonymous Web Hosting? See Which Hosts Deliver the Best (http://www.hostingadvice.com/howto/best-anonymous-web-hosting/) Sean Garrity, 3/15/18
Apache is the web server component of the popular LAMP (Linux, Apache, MySQL, PHP) stack. Though there are many other web stack components these days (e.g., NodeJS, rich clients JS frameworks, various cloud services, etc.), LAMP still remains very popular. The Apache web server has a rich set of features that can be enabled through installing one of the approximately 60 official modules or one of the many other unofficial modules that also exist.
Which Hosting Providers Have the WordPress.org Seal of Approval? (http://www.hostingadvice.com/howto/wordpress-approved-hosts/) Alexandra Leslie, 2/26/18 more how to's (http://www.hostingadvice.com/howto/) »
Over the years, Apache has developed several methods for processing web requests to improve its efficiency (mainly RAM usage and latency). In a world where ever more concurrent web requests needed to be handled by sites, and where the served page sizes got a lot bigger, these newer methodologies were necessary. The Apache request processing methodology can be configured in one of three ways. I’ll break down the three main Multi-Processing Modules (http://www.hostingadvice.com/external/? site=882f788a96a4f71de4f78178aff64dfe4577f46229713bf3a881dbb750f5bec82018be49e13ac722e1d5745fadfd0a3a) (MPMs) below: 1. process model (http://www.hostingadvice.com/external/? site=882f788a96a4f71de4f78178aff64dfe4577f46229713bf35d5a966604e937ee4d32e6fea51316fbb940105a6a3df89b8025ac3537390bf7): This is the original “pre-fork” method; it does not scale well with many concurrent connections, as it consumes a lot of RAM and might even refuse connections at high loads. Smaller sites won’t notice this, but larger sites likely will. 2. worker model (http://www.hostingadvice.com/external/? site=882f788a96a4f71de4f78178aff64dfe4577f46229713bf35d5a966604e937eef0cc1417c9c70bd4842796b95ddbac5f25924dac3ffbd806): This creates a single control process that is responsible for launching child processes. Each child process then creates a fixed number of threads, as well as a listener thread. The listener thread listens for connections and passes them to a thread for processing when they arrive. Though this model scales much better than the pre-fork method, it can still run into scaling issues for very high-traffic sites, due to the single control process bottleneck. 3. event model (http://www.hostingadvice.com/external/? site=882f788a96a4f71de4f78178aff64dfe4577f46229713bf35d5a966604e937eec1565014e3773887ac0d418618a2b4da): This is similar to the worker model, but it creates one listener thread which listens for connections and passes them to a worker thread for processing. This MPM handles long-running connections much more efficiently on a single thread (KeepAlive handling). Since Apache 2.4, the event model has been deemed stable and is now also the default setting if the operating system can support it. You can also try compile-time and run-time options (http://www.hostingadvice.com/external/? site=762f3dd1b6d29f265e08d3a14c0abacae2ded72d9bf10c57f3c36fc61e33bd55e2dfa4895f82f072c038b4977cc808cf6e5f4e2342ef3ba88025ac3537390bf7) for improving Apache performance.
NGINX was created in response to the C10K challenge (http://www.kegel.com/c10k.html) of handling at least 10,000 simultaneous client connections on a single server. NGINX uses an asynchronous, event-driven architecture to handle these massive amounts of connections. This architecture makes handling high and fluctuating loads much more predictable in terms of RAM usage, CPU usage, and latency.
NGINX’s event-driven architecture helps predict RAM and CPU usage, as well as latency, for high/fluctuating loads.
The main difference between NGINX and Apache, in terms of the event models, is that NGINX does not set up extra worker processes per connection. In most cases, the recommended NGINX configuration is running one worker process per CPU, maximizing the hardware’s efficiency. NGINX also has a rich set of features and can perform various server roles: A reverse proxy server for the HTTP, HTTPS, SMTP, POP3, and IMAP protocol A load balancer and an HTTP cache A frontend proxy for Apache and other web servers, combining the flexibility of Apache with the good static content performance of NGINX NGINX supports FastCGI and SCGI handlers for serving dynamic content scripts such as PHP and Python. It uses the LEMP stack: a variation of LAMP using the phonetic spelling of NGINX (Linux, “En-juhn-ex,” MySQL, PHP).
Now let’s compare both web servers in several fields. We’ll find that Apache and NGINX are worthy competitors, but depending on your use case, one may be better suited for your project than the other. Don’t worry, I’ll sum it up nicely in my concluding NGINX/Apache comparison.
Below we’ll contrast the performance of Apache (using the event MPM) with that of NGINX in both static and dynamic content serving roles. Static Content NGINX is about 2.5 times faster than Apache based on the results of a benchmark test (http://www.eschrade.com/page/performance-of-apache-2-4-with-the-event-mpm-compared-tonginx/) running up to 1,000 concurrent connections. Another benchmark running with 512 concurrent connections (http://www.speedemy.com/apache-vs-nginx-2015/), showed that NGINX is about two times faster and consumed a bit less memory (4%). Clearly, NGINX serves static content much faster than Apache. If you need to serve a lot of static content at high concurrency levels, NGINX can be a real help. Dynamic Content A 2015 benchmark comparing dynamic content serving by Apache and NGINX (http://www.speedemy.com/apache-vs-nginx-2015/) found that the Apache event MPM, when paired with the PHP-FPM module, can handle about the same concurrency as can NGINX with PHP. Another web server performance comparison (https://www.conetix.com.au/blog/apache-vsnginx-vs-openlitespeed-part-1) showed similar results. The reason for this is almost all of the request processing time is spent in the PHP runtime environment rather than the core part of the web server. The PHP runtime environment is pretty similar between both web servers.
Speedemy’s web server benchmarking found similar results using both Apache and NGINX to serve dynamic content.
In terms of PHP (and likely other languages as well), the dynamic page server performance is practically equal with a proper Apache module setup (PHP-FPM + FastCGI). If you really want to speed up dynamic pages, you have several options: add a Varnish or Memcached caching layer, switch to a faster PHP runtime (e.g., HHVM), do load balancing, or add more hardware. Unfortunately, the superior static page serving performance of NGINX does not translate to the serving of dynamic pages. Both web servers score about the same on this point.
Apache runs on all kinds of Unix-like systems (e.g., Linux or BSD) and has full support for Microsoft Windows. NGINX also runs on several modern Unix-like systems and has some support for Windows, but its Windows performance is not as strong as that of other platforms. Apache comes out somewhat stronger here.
Both projects have an excellent security track record for their C-based code base. The NGINX code base, however, is significantly smaller by several orders of magnitude, so that is definitely a big plus from a forward-thinking security perspective.
There is vulnerability reporting available for Apache 2.2 and 2.4 (http://www.hostingadvice.com/external/? site=882f788a96a4f71de4f78178aff64dfe4577f46229713bf3eda51b87ef758c32582d0525164fe45fbd92dd08f0fdb1c4). NGINX also has a list of recent security advisories (http://www.hostingadvice.com/external/? site=21d5fde7e545f75d3ea604e2d7ebec44351bdbd0ab065c236d809834c047a70ba29042de84593300876e7862ca510a98). Apache offers configuration tips for DDoS attack handling (http://www.hostingadvice.com/external/? site=882f788a96a4f71de4f78178aff64dfe4577f46229713bf3ac64c08dc7dc0c6680ab0e7084ea35d2eda51b87ef758c322ba8faa28c8c12ef9199892833345f29), as well as the mod_evasive module (http://www.zdziarski.com/blog/?page_id=442) for responding to HTTP DoS, DDoS, or brute force attacks. You can also find helpful resources for dealing with DDoS threats on the NGINX blog (http://www.hostingadvice.com/external/? site=882f788a96a4f71d60b03e67d5b422fcc36fa818dbc560a3a0de01f80c872c91f59b03367eb05a2781f56a29bee8f77e9ac78de6200b5a9014c4bc4c6f6a6aa4b53f8a478c8e95b86cc512249c41a519).
Customizations to the web server can be done through writing modules. Apache has had dynamic module loading for the longest time, so all Apache modules support this. This is, however, not the case for NGINX. In the beginning of 2016, NGINX got support for dynamic module loading; previously, NGINX required the admin to compile the modules into the NGINX binary. Most modules do not yet support dynamic loading, but over time they probably will. Apache clearly leads on this point. Dynamic Module Loading & Modules Both Apache and NGINX have a large and growing set of specific feature modules. Apache Modules: Official Modules (Found in the Modules section of the Apache documentation) Module List on Wikipedia (https://en.wikipedia.org/wiki/List_of_Apache_modules) Unfortunately, a well-maintained list of all third-party modules does not seem to exist yet.
NGINX and Apache both have rich and ever-growing feature sets, but the best use cases vary for each web server.
NGINX modules: Official Modules (found in the Modules Reference section of the NGINX documentation) Third-Party Modules (http://www.hostingadvice.com/external/? site=882f788a96a4f71d60b03e67d5b422fc29fc5a18d07c355c2b139fa63b1f15111afa6c149e3542690f7a415482ea2a5d) It’s not easy to say if Apache or NGINX has a clear advantage here, but most of the core needed module functionality (e.g., proxy-ing, caching, load-balancing, etc.) is available for both web servers. NGINX looks stronger in the area of acting as a reverse proxy for TCP and email (SMTP, IMAP, POP3) connections. In the area of media streaming modules, the commercial NGINX Plus version also looks stronger. Apache .htaccess NGINX does not support something like the Apache’s .htaccess file. Using .htaccess files, one can override system-wide settings on a per directory basis; however, for optimal performance, these .htaccess directives should be included in the main configuration file(s) whenever possible. This is not possible in the case of shared hosting environments, but it can add a lot of flexibility for shared hosting users.
The documentation for both Apache (http://www.hostingadvice.com/external/? site=882f788a96a4f71de4f78178aff64dfe4577f46229713bf35d5a966604e937ee8c1cfaaa8b1f2fac) and NGINX (http://www.hostingadvice.com/external/? site=21d5fde7e545f75d3ea604e2d7ebec442a9cc8503ffab63475c038cdd144d44f) are excellent, including the NGINX wiki (http://www.hostingadvice.com/external/? site=882f788a96a4f71d60b03e67d5b422fc29fc5a18d07c355c2b139fa63b1f15117cb5d9c8f576eb4b). NGINX also offers online and on-location training sessions on a variety of NGINX topics — including exam certifications.
Apache community support is done through mailing lists, IRC, and Stack Overflow (http://stackoverflow.com/questions/tagged/apache). Commercial Apache support is available from a number of third-party companies, such as OpenLogic, but no official list is maintained by the Apache Foundation. NGINX has community support through mailing lists, IRC, Stack Overflow (http://stackoverflow.com/questions/tagged/nginx), and a forum. The company behind NGINX offers a commercial product called NGINX Plus, which has support for a set of extra features regarding load-balancing, media streaming, and monitoring.
Both web servers, in their latest versions, can compete with each other in most areas. For static content NGINX is king, but for dynamic content the performance difference is quite slim. NGINX does shine with some of its more advanced features (media streaming, reverse proxying for nonHTTP protocols), as well as its commercial support and training. Shared hosting (http://www.hostingadvice.com/reviews/cheap/) users might prefer the convenience of the Apache .htaccess file, and Apache better supports loading various dynamic modules, a feature that NGINX only recently added. NGINX is mainly used for VPS hosting (http://www.hostingadvice.com/reviews/vps/), dedicated hosting (http://www.hostingadvice.com/reviews/dedicated/), or cluster containers. High-traffic website ownerss that need to serve a lot of static content and/or media streams will probably prefer NGINX (or use a combination of Apache and NGINX). In most other website use cases, either web server will do the job just fine. To get started with either web server, you’ll need a solid Linux hosting provider. Luckily, our team compared the best providers and can point you in the right direction for Linux hosting for shared or virtual servers.
Well, there you have it. If you still have questions before you select NGINX or Apache for your next web project, be sure to let us know below!
Ask a question and Alexandra will respond to you. We strive to provide the best advice on the net and we are here to help you in any way we can. 12 Comments
HostingAdvice.com
Recommend
1
Login
Sort by Best
Share
Join the discussion… OnceBuilder CMS • 7 months ago
Still don't know which is better... 5
• Reply • Share ›
Mohammed Joraid
OnceBuilder CMS • a month ago
Are you serving more dynamic contents or static contents? Apache has more documentation and widely used with .htaccess. NGINX is newer. The ultimate solution is to use both together where Apache for processing dynamic content and use NGINX to deliver static (cashed) contents. • Reply • Share ›
Paruba • 7 months ago
Wow! This is the best Nginx vs. Apache comparation I found after a long research! I have a question please: regardless of served content (static or dynamic), do you think Nginx would be a better choice in a VPS with multiple CPU (ie. 4 CPU)? I mean, does Nginx can better take advantage of multiple CPUs than Apache? Thank you! 4
• Reply • Share ›
Rimom Aguiar • 2 months ago
excellent article, for me apache is better because I am gonna share my server and it is easier to do using apache (virtual servers, .htaccess and etc...), but if my next project is for an exclusive application, definitely I gonna use nginx. 1
• Reply • Share ›
TickSeeker • 3 months ago
Amanda you did a very good job here. Thank you very much! 1
• Reply • Share ›
Mohammed Joraid
TickSeeker • a month ago
Amanda who? • Reply • Share ›
zmtnman • 17 days ago
Hey there Alexandra - This article was totally stupendous. So do you have recommendations of a company or comany(s) that would want to configure theses types of custom configuration or have you already? Most I talked with on one of your list have one ot the other not able to use both like a front end Apache and Nginx proxy dynamite handler? Sounds like it would be a speedy little setup. Also goes out to anyone that can answer any legit conpany(s) that can. • Reply • Share ›
Ted Wood • 25 days ago
I still run Apache on my cPanel server, but have Nginx configured as a proxy for higher performance. On my 10+ Ubuntu servers, and my local Mac development machines, I switched to pure Nginx. Much happier with this setup than I was with the previous many years as an Apache user. I just find the configuration easier to understand. Don't need .htaccess-like functionality in my apps, so not missing that feature. • Reply • Share ›
Howard Milstein • 5 months ago
Hi Im getting great scores ( on pingdom..97 google page 99 and gtmetrix 100 ..however, many times on web page test and byte check, my TTFB IS DISMAL...and it also varies greatly during different times of the day. What, if any, is a good solution? (siteground, middle plan) PS maybe upping to siteground GO GEEK. OR dedicated? Also..Siteground says they use Apache and Nginx.(not understandable to me at all) Thanks Howard • Reply • Share ›
Venu Roopani • 9 months ago
which is better to act as loadbalancer? why • Reply • Share ›
Rahul Kumar • a year ago
I have done a lot of searches on google for the keyword " Apache vs Nginx". I have created a droplet on digitalocean with ubuntu 14.04 BUT I was stucked at the point which server should I use. Now, after reading this article I'm sure that nginx is better than any other servers. I'll use wordpress. Can you help or suggest me a link show that I can learn how to setup nginx so that it can serve wordpress content as static html? • Reply • Share ›
Joel Kuiper
Rahul Kumar • a year ago
Hi Rahul, Though this is quite some time after you asked the question, You can have Nginx serve static content from WordPress but you have to use a plugin like WP Super Cache (or similar page caching plugins) what these plugins do is create static HTML pages from your dynamic WordPress pages. The plugins will also rewrite requests to your site so that if possible the server will send a static HTML file instead of doing a dynamic request. Hope this helps! Joel • Reply • Share ›
Subscribe
25 Like
Add Disqus to your siteAdd DisqusAdd
Like this article on Facebook
Tweet
Privacy
Tweet this article on Twitter
Share this article on Google+
Alexandra Leslie’s interest in website administration was sparked in her teens, priming her for a fast-paced career in managing, building, and contributing to online brands, including HostingAdvice, Forbes, and the blogs of prominent hosting providers. She brings to the table firsthand experience in reviewing web hosts, perfecting website design, optimizing
Alexandra Leslie Follow
content, and walking site owners through the steps that add up to a successful online presence. Today, she combines her extensive writing experience with technical understanding to unpack some of the most complex topics that daunt novice website owners, as well as the subjects that excite veteran technologists within the HostingAdvice readership.
Jacob Nicholson • 01/08/2015 Roberto Sanchez • 08/05/2014 (http://www.hostingadvice.com/how-
(http://www.hostingadvice.com/how-
to/change-file-permissions-
to/install-nodejs-ubuntu-14-
linux/)
04/)
Roberto Sanchez • 04/27/2016 PJ Fancher • 12/03/2015 (http://www.hostingadvice.com/how-
(http://www.hostingadvice.com/how-
to/find-free-domain-with-
to/linux-add-user-to-group/)
email-hosting/)
Contributing Experts (http://www.hostingadvice.com) Our mission: to inform and educate our visitors about the
| About (http://www.hostingadvice.com/about/)
Follow Us
— Sections — — Best Hosting —
world of Web Hosting. Home (http://www.hostingadvice.com/)
Latest Advice
— Host Reviews —
(https://www.facebook.com/HostingAdviceCom)
(https://twitter.com/Hosting_Advice)
| Contact (http://www.hostingadvice.com/contact/) | Privacy (http://www.hostingadvice.com/privacy/) | Terms (http://www.hostingadvice.com/terms/)
(https://plus.google.com/+Hostingadvice/)
| Sitemap (http://www.hostingadvice.com/sitemap/) © 2018 HostingAdvice.com | Digital Brands | All Rights Reserved Disclaimer: Great efforts are made to maintain reliable data on all offers presented. However, this data is provided without warranty. Users should always check the offer provider’s official website for current terms and details. Our site receives compensation from many of the offers listed on the site. Along with key review factors, this compensation may impact how and where products appear across the site (including, for example, the order in which they appear). Our site does not include the entire universe of available offers. Editorial opinions expressed on the site are strictly our own and are not provided, endorsed, or approved by advertisers.