The rise in popularity of nginx and the steady decline of Apache
in the web server market has caused many to believe that the choice has
become clear cut for new deployments. Indeed, in my most recent larger
scale server setup I ended up choosing nginx for the job - but should I
have?
The internet appears to have fallen out of love with Apache, the faithful workhorse that has dominated the landscape for the past decade plus. While it still powers the majority of websites out there, Apache has steadily lost ground to nginx (engine-x) over the past few years.
Nginx has become popular due to its event driven design which can make better use of today’s computer hardware that Apache’s process driven design. The end result is that nginx can serve more concurrent clients with higher throughput than Apache on the same hardware. In some cases. The often overlooked condition with the choice is what exactly you’re going to be doing with your servers.
Nginx excels at serving static content, it can do it more efficiently than Apache can, but Apache can serve static content quickly as well. Static content is the easy stuff for any web server so high traffic sites strive to generate static content from their more complicated back end systems in order to fulfill the demand of their users quickly. Throw PHP in the mix and things get a lot more difficult.
The most important question when you’re choosing a web server setup is how you’re going to use the server. If you’re going to be serving a single site and this server is dedicated as a web server with a separate database server, you will likely be able to find some gains by using nginx over Apache if you have high traffic. As an additional benefit, nginx has configuration features which make it easier to scale than Apache if necessary. If you’re going to be hosting many sites and many applications with this server, like a bunch of Wordpress sites, the answer is less clear. In that case PHP becomes much more of a bottleneck than either of the web server choices.
You might be saying to yourself, well, if PHP is the problem with both of these web servers and in serving static files nginx is faster, why wouldn’t I go with nginx? Apache has its advantages. It’s a mature and capable platform and pretty much has universal support in the linux world. Things that ‘just work’ out of the box with Apache may need additional research and configuration under nginx. Control panels and automatic configuration tools may not be available for nginx yet. Your staff might be a lot more familiar with Apache and much more capable of diagnosing issues. Those benefits shouldn’t be underestimated.
The performance gains of nginx are negligible for the vast majority of scenarios out there. Out of the billions of websites being hosted, very few are receiving meaningful traffic. You should be realistic about your requirements and also about your skill set. If you are looking to use a new technology as a learning exercise for your personal blog, by all means use whatever platform you’re interested. If you’re setting up a hosting server or a critical business application, weigh your options carefully. Trying to force everything into nginx because you heard it will be drastically faster could be a mistake.
In the end, the best strategy is formed by a combination of technologies rather than a simple reliance on a web server platform. Sites which attract a lot of traffic will take a multi-layer approach to their architecture and the web server will be a smaller component in the grand scheme of things. More average sites should consider going with what they know best and comparing that against the performance of the specific type of site they’re hosting. Apache is still a great engine and is still the most popular. As nginx matures it will become even better, perhaps even surpassing Apache within the next five years.
As for choosing between the two, the answer is that it depends. If you’re going to host a Wordpress site, a very common scenario, I’d argue that both will do the job well. There are performance gains to be had by using nginx if you cache your site (which you should) but it comes as the expense of some out-of-the-box compatibility and a potential learning curve. If you’re running a PHP application, you’ll see bigger gains by using an opcode cache like APC than you would by switching web servers. My point is, nginx isn’t a silver bullet. Hastily dumping Apache because it’s not what the cool kids are using could end up hurting you in the end.
The internet appears to have fallen out of love with Apache, the faithful workhorse that has dominated the landscape for the past decade plus. While it still powers the majority of websites out there, Apache has steadily lost ground to nginx (engine-x) over the past few years.
Nginx has become popular due to its event driven design which can make better use of today’s computer hardware that Apache’s process driven design. The end result is that nginx can serve more concurrent clients with higher throughput than Apache on the same hardware. In some cases. The often overlooked condition with the choice is what exactly you’re going to be doing with your servers.
Nginx excels at serving static content, it can do it more efficiently than Apache can, but Apache can serve static content quickly as well. Static content is the easy stuff for any web server so high traffic sites strive to generate static content from their more complicated back end systems in order to fulfill the demand of their users quickly. Throw PHP in the mix and things get a lot more difficult.
The most important question when you’re choosing a web server setup is how you’re going to use the server. If you’re going to be serving a single site and this server is dedicated as a web server with a separate database server, you will likely be able to find some gains by using nginx over Apache if you have high traffic. As an additional benefit, nginx has configuration features which make it easier to scale than Apache if necessary. If you’re going to be hosting many sites and many applications with this server, like a bunch of Wordpress sites, the answer is less clear. In that case PHP becomes much more of a bottleneck than either of the web server choices.
You might be saying to yourself, well, if PHP is the problem with both of these web servers and in serving static files nginx is faster, why wouldn’t I go with nginx? Apache has its advantages. It’s a mature and capable platform and pretty much has universal support in the linux world. Things that ‘just work’ out of the box with Apache may need additional research and configuration under nginx. Control panels and automatic configuration tools may not be available for nginx yet. Your staff might be a lot more familiar with Apache and much more capable of diagnosing issues. Those benefits shouldn’t be underestimated.
The performance gains of nginx are negligible for the vast majority of scenarios out there. Out of the billions of websites being hosted, very few are receiving meaningful traffic. You should be realistic about your requirements and also about your skill set. If you are looking to use a new technology as a learning exercise for your personal blog, by all means use whatever platform you’re interested. If you’re setting up a hosting server or a critical business application, weigh your options carefully. Trying to force everything into nginx because you heard it will be drastically faster could be a mistake.
In the end, the best strategy is formed by a combination of technologies rather than a simple reliance on a web server platform. Sites which attract a lot of traffic will take a multi-layer approach to their architecture and the web server will be a smaller component in the grand scheme of things. More average sites should consider going with what they know best and comparing that against the performance of the specific type of site they’re hosting. Apache is still a great engine and is still the most popular. As nginx matures it will become even better, perhaps even surpassing Apache within the next five years.
As for choosing between the two, the answer is that it depends. If you’re going to host a Wordpress site, a very common scenario, I’d argue that both will do the job well. There are performance gains to be had by using nginx if you cache your site (which you should) but it comes as the expense of some out-of-the-box compatibility and a potential learning curve. If you’re running a PHP application, you’ll see bigger gains by using an opcode cache like APC than you would by switching web servers. My point is, nginx isn’t a silver bullet. Hastily dumping Apache because it’s not what the cool kids are using could end up hurting you in the end.
No comments:
Post a Comment