When it comes to the technicalities of hosting WordPress powered websites, everyone knows about Apache and NGINX, two of the most popular server software out there.
Powering 45.2% of all websites, Apache still dominates the server market. The LAMP (Linux, Apache, MySQL, and PHP) stack is famous for flexibility and performance. In fact, for a vast number of developers, this is THE development stack of choice.
However, over the last few years, NGINX has been slowly winning the interest of developers worldwide. Today, it handles 40.0% of total web servers and stands second in the competition.
Apache and NGINX are both open-source web servers. Interestingly, given the long history and high usage of these software for hosting WordPress websites, it is surprising that the WordPress community regularly face questions such as: what is NGINX/Apache? How they are different (and similar)? Which one should you use? Or, can you use NGINX with Apache? In this guide, I have covered all these questions.
Table of Contents
What is NGINX?
Released in late 2002, NGINX was developed to “serve the needs of the new millennium”. Igor Sysoev, its founder, initiated the project to focus on high concurrency, high performance, and low memory usage. Originally created for the Russian web portal, Rambler, it was adopted by many high traffic sites because of its rock-solid performance.
NGINX (pronounced as “engine-x”) is an open-source software for web serving, caching, media streaming, reverse proxying, load balancing and more. The software server is designed to maximize performance while using minimum resources.
NGINX was created to solve the C10k, a real-world problem to handle a large number of visitors at the same time. C10k is a serious challenge that refers to a server handling ten thousand concurrent connections.
NGINX is a highly optimized, very light and fast web server built for sustained performance under increasing stress (number of request and number of concurrent users). Considering the advantages, it comes as no surprise that a number of WordPress powered websites are moving towards NGINX hosting.
What is Apache?
Apache, the most popular web server till date is developed and maintained by the Apache Foundation.
Apache is known for its reliability, compatibility, and an impressive range of features and support almost all popular server-side languages including PHP, Python, and Perl.
Back in 1995, there was no cloud hosting and less than one percent of the world had access to the Internet (Need a flashback? Here it is). It was then that the first version of Apache was released, and it was perfect in every possible sense. Even today, Apache has far more features than any other server software. And therein lies the problem – not many developers need so many features for the majority of the projects they work on daily basis.
Since Apache is easily customizable and can be tweaked to suit the technical capabilities of almost every hardware setup, it is easy to see the reasons behind the popularity of Apache as the server software of choice.
NGINX vs Apache
The major difference is how NGINX and Apache handle communication between a browser and the web server.
Apache uses keep-alive or a forked threaded solution, which keeps a connection open to each user. On the other hand, NGINX uses a non-blocking event loop, which pools connections working asynchronously via worker processes.
When it comes to flexibility, Apache has no competition. The latest version offers an implementation of Multi-Processing-Modules (MPM) architecture. This mixes several threads and processes and provides performance equivalent of event-based web servers.
NGINX, on the other hand, is extremely light, secure and fast. It has almost all the features that Apache implemented in its latest version. NGINX serves static content quickly and can handle thousands of requests per second.
However, developing modules for NGINX’s rather complex architecture isn’t as simple as developing modules for Apache. This is another very important reason behind the high adoption rate of Apache in the general user community.
According to Google Trends, NGINX is gaining ground rapidly, eating up into the Apache’s share.
However, Apache is still leading the server market despite the increasing NGINX adoption.
Source: Google Trends
Check Which Web Server You Are Using?
You can easily check which web server your website is using.
Simply visit your website, go to the DevTools/Inspect Element, Network (1) tab and refresh the page. Click on the main page (2) of a site, look for Server (3) in Headers view as shown in the image below.
Note that the header might not always reveal the right information if a website is behind a proxy service like Cloudflare.
WordPress with NGINX or Apache?
While Apache and NGINX are the market leaders, the reasons behind their popularity are very different:
Apache for power and NGINX for speed.
However, both NGINX and Apache have downsides. Apache consumes huge hardware resources (particularly server memory), while NGINX (great for static content) needs the help of PHP-FPM or similar modules for dynamic content.
According to the official WordPress requirements:
We recommend Apache or NGINX as the most robust server for WordPress, however, any server that supports PHP and MySQL will do.
Many WordPress users get confused between the two because of a simple reason: Many WordPress hosting guides assume Apache as the web server because it is often the default choice of a majority of the web hosting providers because of its compatibility and ease of use.
While WordPress can also be hosted on NGINX without the need of Apache at all, NGINX does not offer .htaccess and thus WordPress won’t be able to use the .htaccess file. If you host your WordPress website on NGINX, you might need to regularly re-configure NGINX for WordPress plugins that use .htaccess file.
NGINX is ideal for serving static content and this is where it outshines all competition. A typical WordPress post comprises of static content such as CSS, scripts, and images, NGINX could serve both a server and cache.
To make the most out of NGINX, experts suggest using a cookieless domain for static assets so that the content is truly cached by the web browser. Using a subdomain like static.example.com is ideal for serving the static content.
On the flip side, when it comes to serving dynamic content, NGINX is not as capable as Apache.
For WordPress websites, try to use Apache with NGINX (NGINX as a reverse proxy, and Apache at the backend). This allows your WordPress site to use .htaccess file AND get the benefits of NGINX’s performance for serving static content. This is a powerful combination with a powerful backend and robust frontend.
Configure NGINX with Apache
If you also want to set up NGINX with Apache, you need to have the SUDO (root) access to the server and follow the step-by-step guide created by DigitalOcean, one of the best cloud hosting providers out there.
Why Cloudways Use NGINX with Apache? – The Perfect Combination
The typical hosting industry saying goes:
If you want speed, it’s NGINX.
If you want convenience, go with Apache.
Considering the benefits of an Apache-NGINX combo, our aim is to ensure fast loading websites. This is the reason why we come up with our custom recipe by combing NGINX with Apache along with Varnish. As a result, we are among the fastest WordPress hosting providers.
Not only this, we tested Apache with NGINX combination with some tweaks on a WooCommerce store with thousands of dummy products.
This is what you can achieve by combining NGINX with Apache for a WordPress site.
NGINX is very fast for static content and Apache is popular for its power and the backend compatibility. Comparing NGINX with Apache would not be fair, as each has their own benefits and drawbacks. Choosing between the two could be difficult and it all comes down to your needs, current and expected traffic and potential future growth.
We highly recommend taking the best of both worlds by combining Apache with NGINX (like ThunderStack, our custom hosting stack).
Which web server you are using and why? Ever tried Apache with NGINX? Feel free to share your experience.
Mustaasam is the WordPress Community Manager at Cloudways - A Managed WordPress Hosting Platform, where he actively works and loves sharing his knowledge with the WordPress Community. When he is not working, you can find him playing squash with his friends, or defending in Football, and listening to music. You can email him at firstname.lastname@example.org
Start Growing with Cloudways Today!
We never compromise on performance, security, and support.