This is a guest post written Austin W. Gunter, the Brand Ambassador of WP Engine’s Managed WordPress Hosting Platform.
WordPress’s development has been intertwined with Apache since the beginning. WordPress was built to be served on Apache. Recently Nginx has risen to prominence to serve traffic from 11.4% of all known traffic.
Automattic moved WordPress.com over to Nginx, and managed WordPress hosts like WP Engine, and ZippyKid have adopted the technology as well. WordPress.com has publicly stated they have thousands of servers serving hundreds of thousands of requests per second. I spend most of my days talking about complicated server technology, but I hadn’t found a good resource to actually explain, in conversational terms, why Nginx is cool, why people are using it, and what the tradeoffs are between it and Apache. This post is intended to explain what Nginx is at a high level, not provide a “how to” for folks who may want to install it themselves.
First off, Nginx and Apache are not equal, but what makes them different? What makes Nginx suited to handle high performance web hosting tasks – such as serving an onslaught of concurrent requests when a post makes the front page of HackerNews or Reddit? What do you still need Apache for?
CK10 Problem
Nginx was developed, in part, to solve the C10k problem, or optimizing web server software to handle a large number of clients at the same time. C10k stands for concurrent ten thousand connections. When a blog post hits the front page of HackerNews or Reddit, thousands of visitors can arrive at your site at once. Nginx is event-based, and is fantastic at responding to concurrent requests.
Concurrent Connections
Nginx is designed to handle thousands of concurrent connections with low CPU usage. It is a non-blocking event-driven web server, using a single process (or a small number of processes) to handle connections using evented I/O. Apache has several Multi-Processing Modules (“MPM”), but for most Linux systems, Apache’s default is the “prefork” MPM. Apache recommends using the “worker” MPM unless you’re using PHP – since PHP isn’t thread safe. A piece of code is thread-safe if it only manipulates shared data structures in a manner that guarantees safe execution by multiple threads at the same time. Nginx’s event-based” design allows it to serve data quickly, and with many concurrent connections, but we sacrifice Apache’s ability to process PHP
Additionally, Apache is limited by how many threads it has CPU to run, and Apache processes are costly. At 50-300MB per process, after the of concurrent processes, default is 256, Apache’s performance will decrease. Nginx, on the other hand, can handle 10,000+ concurrent connections using about 2MB of memory, never spawning new threads or processes. That’s absurdly scalable.
Static Assets
Nginx is the king of serving statics. Where Apache has to load mod_php into memory to serve an image request, Nginx will deliver statics like images, javascript, css, html, etc directly to the browser with its blazing fast I/O. Conceptually, Nginx just transfers data, never processing it, which is why it requires so few resources to run.
PHP
So how do we translate WordPress PHP with Nginx? Apache often bundles PHP with its processes, but to process PHP, Nginx needs to be paired with an external process like FastCGI, PHP-FPM, or HTTP. This can be done fairly easily. What’s more, by separating processes we can actually see more speed gains with Nginx. It will forward requests to process PHP externally, and send the response back to the browser.
Additionally, these can be configured to process different requests on various servers. This is a big deal for web host or sysadmin, because it means they can specify which requests go to which server, reducing request backlog. It also means that server and application processes can be restarted separately.
Proxy Caching
WordPress.com makes heavy use of Nginx’s ability to proxy_cache. You can program Nginx to send requests to the backend, but on the way back out have it hold the request on disk for “X seconds” so that the next requests can serve the page without having to go back to Apache for each new user.
3rd Party Modules
With Nginx gaining prominence, we’re seeing developers start to create cool modules we can compile into Nginx that add functionality we might need. As with any open-source project, these modules will likely be a key source of innovation on the web server.
Those are some huge advantages. But it’s important to note that Nginx isn’t an appropriate solution for shared hosting solutions, and it’s certainly not necessary for everyday WordPress blogs that don’t see high levels of traffic. Under minimal traffic, visitors may not notice any speed difference between Apache and Nginx. You want to serve WordPress off of Nginx if you expect to someday experience traffic spikes, and want to keep your site up and loading pages at sub 1.5seconds. Under load Nginx’s event-based processing, ability to serve statics quickly, and proxy_cache requests give it the ability to serve tens of thousands of connections on 2MB of CPU. That same traffic would cause Apache to commit harakiri.
Because Nginx is so scalable, Automattic, WordPress.com, and Managed WordPress hosts like WP Engine or ZippyKid have adopted the technology, usually along with Apache to serve PHP, and are using it to provide massively scalable hosting for tens of thousands of domains. Apache is still the place to process complex requests, but it cannot keep up with the scalability of Nginx.
What is your site running on? Have you considered installing Nginx to serve WordPress? Let me know in the comments what you’re using.



Jonathan Dingman is a passionate blogger who loves writing about WordPress news, reporting on events, theme releases, awesome plugins, and more. He started using WordPress in 2004 and ran the first WordCamp NYC in 2008.
Switched to Nginx a few weeks ago after growing tired of getting emails from my host saying I’d gone over my RAM allocation. Spent hours trying to configure my site to cope with heavy traffic on Apache but no amount of caching & .htaccess tweaks made a difference. Switched to Nginx, created a basic .conf and haven’t looked back. RAM usage is under control and the site is more responsive. Brilliant.
Gavin,
Thanks for the comment! I’m glad you’re having great luck with Nginx. I think it would be cool to see the before / after stats of your site speed since making the switch.
Great article!
Switched completely to nginx a few days ago after using it as a reverse proxy (static content) for Apache. Honestly, it was the best decision I’ve ever made and I haven’t looked back since. The only reason I held back initially going all nginx was due to rewrite’s which I wasn’t comfortable with at the time but I’ve grown accustomed to it and now prefer it to Apache’s mod_rewrite. Nginx’s configuration, once you learn it, is 10x more intuitive and easier to manage than Apache, imo. Also, mem usage went from ~300mb to ~80mb after switching over to nginx… yeah.
Thanks for the comment, man.
I’m glad you’re finding nginx easier and more intuitive. They definitely got to learn from Apache’s mistakes when creating the platform, and you’re experiencing the results in the ease of use AND the dramatic difference in the memory.
A few months ago I had my VPS setup with Nginx as a reverse proxy infront of Apache. Since moving hosts I went back to an Apache only setup, and I’m wondering how you went about changing from Apache to Nginx?
The fact that pretty much all the sites running on WordPress (the only non-WordPress site I have is a Bug Genie install) made the switch much easier because the nginx wiki has a great article for a sample WordPress setup. I also read a bunch of blogs on how people setup their servers and I kind of got a feel for the best practices I should be implementing on my setup. If you want any of the resources I looked at or the config of my server, I’d be more than happy to post that info here or email you!
Most of my servers run Nginx latest with php5-fpm. Great performance!
For people in need of htaccess I run Apache2/Lighty with php5-fpm or php-fcgi respectively.
Hey Daniel, thanks for sharing that part. Great suggestion for folks that need .htaccess!
Another great article on Nginx.
I’m not sure what it means by “Under load Nginx’s event-based processing, ability to serve statics quickly, and proxy_cache requests give it the ability to serve tens of thousands of connections on 2MB of CPU”. I guess there is a mis-placed punctuation mark and 2MB of CPU?
Well, it looks like the period is outside the quotation marks, but the sentence reads the way I intended. What can I clear up for you?
Thanks for the reply. The typos are fixed by now. I was confused by 2MB of CPU.
I prefer nginx, because my vps is very small and has only 512MB ram. Apache ist just too big and a resourcemonster.
RAWR the resourcemonster!
Kidding… Thanks for the comment, Maltris. When did you switch over to Nginx?
I switched 1 year ago. At first i was using the 0.7 package from the debian resources, later then i wanted to take benefit of the new versions and i changed to the dotdeb-Repo.
Currently I manage a website that is running WordPress on Apache but I am pushing the limit of available memory, our server runs two WordPress with 256MB of RAM. I have disabled a lot of unnecessary Apache modules but we’re still pushing the memory limit. So I am in the process of setting up a test machine with NginX so I can being migrating over. If all oes well, I might even set up a varnish cache server in front of NginX.
Hey Ben,
That sounds like a sound idea. Nginx should save you a ton of memory. Another question, do you have a CDN set up on your blog? That will also make a huge difference.
Thanks for this, I’m still not 100% sure whether to change to nginx.
Based on what you have said, why doesn’t every wordpress site use nginx? Are there any disadvantages?
I would suggest not switching over on a whim. Become familiar with a typical nginx setup first on a test server because I know firsthand that it’s much, much different from Apache in terms of configuration and fine tuning. But if you do decide to switch, like I’ve commented on here previously, the configuration makes way more sense that Apache’s and the performance increase is definitely worth it.
Also, most hosting providers (many of which I assume, host WordPress installs) still use Apache because part of the server config (including rewrites) can be configured through .htaccess on a per-directory basis, something which nginx does not support. And since most shared hosting providers use cPanel with an Apache setup, I just don’t think it’s worth the performance increase and headache for them to migrate when there isn’t really a pressing reason to switch.
+1, Mr. Owen.
I agree that switching things like this isn’t mission critical unless your performance is getting in the way of your business model or a launch. For that matter, any sort of hosting migration is usually a big deal and not worth it unless you’re in serious pain. I tell that to folks who are considering a migration to WP Engine. I love our hosting, but migrating is a big deal and if things aren’t broken, or you don’t *need* the improvement, it’s something to look at more than once.
However, I also know that most talented developers look for the evidence that they need and their mind is made up very independently of almost anything I (or anyone else) could say. If you’re down to move to get the benefit out of Nginx, then you should. Just be prepped for a bit of time making the tweaks and adjustments it will require.
I switched to Nginx a one year ago. I was very interessted into the project and did not like Lighttpd.
Turns out, Nginx is just fantiastic, and is definitely the way to go.
Routing requests with Apache feeld kinda stupid to me nowadays…