We all know about these two web servers, but which one should you be using?
That is a question that troubled me for months, and I hope this post will help you decide.
NGINX is much newer than apache, and was built to help with the high number of concurrent connections most websites require. It is known for using less resources than apache, serving static resources in under a second, even with thousands of requests, and it does have a pretty big community. The biggest drawback is that it can’t process PHP, so it relies on passing all PHP requests to another program to handle that, which can even be apache.
Apache is much older than NGINX, and has a bigger market share. It can be more resource intensive than NGINX, but has more or less been fixed with mpm_event, which decreases resource usage by a noticable amount. Unlike NGINX, you can add or remove modules as you want, without needing to recompile it. Also, there are many more modules available for apache, such as mod_evasive and mod_qos, which protect against DoS and slowloris attacks.
Which one is better?
Well, the one you should use largely depends on what your website is, and how much traffic you get. If it’s 100% PHP, and you don’t get that many visitors, then Apache will do just fine. If it’s mostly PHP, and you get lots of visitors, you should use both; have NGINX server any static files, and pass on other requests to apache, giving you the best of both web servers.
Another thing to consider is if you’re the only user on that server or not. If there are multiple websites on one server, each run by different people, you more or less need apache for it’s .htaccess files, which allow for configuration changes without editing the main config file. Although this does slow the site down a bit, sometimes you just need it. This is largely the reason many hosting companies use apache; they can have thousands of sites run by different people on one server without needing to give each one the ability to break it for everyone.
I choose Apache
I’ve already posted about this, but for now I’m sticking with Apache. A ton of plugins require it, and I don’t have the time to convert it all into something NGINX can understand. Also, according to WP Super Cache, htaccess requests use less resources than PHP requests, so if you can use that for rewriting, you server could technically be faster than NGINX, although that is unlikely.
Use apache if you need .htaccess, or if your site is built with (mostly) PHP. If your site is static(e.g. a Jekyll Blog), then choose NGINX. If you can’t choose, use NGINX as a reverse proxy for Apache.