When it comes to the technicalities of hosting WordPress powered websites, everyone knows about Apache and NGINX web server, two of the most popular server software out there.
Powering 45.2% of all websites, Apache web server 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, the NGINX web server 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 their high usage for hosting WordPress websites, it is surprising that the WordPress community regularly face questions such as: what is NGINX or Apache web server? 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.
What is NGINX?
Released in late 2002, NGINX web server 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 open-source software for web serving, caching, media streaming, reverse proxying, load balancing and more. NGINX web 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 supports 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 web server 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 a 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 web 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 web server uses keep-alive or a forked threaded solution, which keeps a connection open to each user. On the other hand, the 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, the NGINX web server is gaining ground rapidly, eating up into the Apache’s share.
However, Apache is still leading the web server market despite the increasing NGINX adoption.
Source: Google Trends
NGINX vs Apache: Comparison Chart
According to the differencebetween.net, Apache and NGINX web server are conceptually close to each other but are rivals in web hosting business.
NGINX vs Apache (In a Nutshell)
For static content, NGINX is king but for dynamic, Apache has better support for various modules. The website owners having a lot of static content will probably prefer NGINX or use NGINX with Apache for better flexibility.
Check Which Web Server You Are 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 NGINX and Apache web servers 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 web 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 web server 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 your WordPress website is 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 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 web server.
For WordPress websites, try to use NGINX with Apache (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 web server, 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.
A few months back, we created a WordPress staging environment and tested this combination. We tweaked our bare-bone WordPress site a bit and then started testing. The site loaded up in just 79ms.
Not only this, we tested NGINX with Apache 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.
Again, the NGINX web server 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 its 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 web hosting stack).
Which web server you are using and why? Ever tried Apache with NGINX? Feel free to share your experience.
Start Growing with Cloudways Today!
We never compromise on performance, security, and support.
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