Scalability Blog

Scaling tips, insights, updates, culture, and more from our Server Experts.
 

5 Ways To Speed Up Your Website With Nginx Web Server

We’ve have been using Nginx server for nearly 5 years now at ServerStack with amazing results. Our favorite implementation is something we’ve nicknamed “Apachix” which is a Nginx reverse proxy to an Apache server. This provides a transparent configuration that it requires no code changes to your application, allows you to continue using .htaccess files and delivers all of the performance boosts that are associated with Nginx.

Recently we ran a set of benchmarks to gauge how well Nginx can outperform Apache. The best results were delivered by Nginx combined with PHP-FPM, and we tested it against Apache running with mod_php. What we saw was an overall 300% increase in site performance based on successful concurrent requests per second, and the amount of total requests that were served during the test period.

Nginx consistently beats Apache in high concurrency environments, and not only does it deliver faster performance it also uses less memory. This means you can do more with the exact same dedicated server you already have. This is worth repeating, instead of upgrading processors or memory, or adding another web server to your account, just switch your web server over to Nginx and instantly gain the performance advantages.

Our fully managed hosting means you’ll gain all of our expertise in running and configuring Nginx server for high performance hosting environments. Here I’ll detail the top 5 configurations that will dramatically improve your website performance.

1. Use Nginx server as a static web server

Since Nginx runs as a high performance web server utilizing very little resources, it is ideal to deliver static content instead of Apache. Not only does Nginx use very little resources but its code is designed to allow a very large number of simultaneous (concurrent) connections. It is also very good at answering slower clients like mobile phones without tying up the server. Overall you’ll see a 2-3x improvement in website speed if your static content is served via Nginx.

2. Use Nginx server as a reverse proxy to Apache web server

This is our favorite upgrade as it requires no code changes, all of your applications continue to work exactly as they did, including .htaccess files. One of the hardest things that we’ve heard from our customers about switching to Nginx is having to rewrite all the rewrite rules. This can be the trickiest part of the migration to Nginx. With Nginx proxying requests to Apache on the back end your application just runs exactly the same way as it did in Apache. All the performance without any of the pain.

3. Use Nginx with FastCGI PHP server

Nginx combined with a FastCGI PHP server like PHP-FPM produces the most powerful PHP server available. This is the most effective way to serve PHP based sites. The most popular software packages that run on top of this are WordPress, Drupal, Joomla, OpenX and ExpressionEngine. In this environment Nginx is serving all of your static content and the PHP-FPM daemon is processing all of your dynamic php web requests. Overall you’ll see a 300-400% increase in performance as compared to a traditional Apache + mod_php setup.

4. Use Nginx server as a cache proxy

Instead of having to dynamically generate every request that comes to your website, Nginx has a built in cache system. This will allow dynamic requests such as PHP, Java or any dynamic page to be cached directly on the server thereby reducing the load on your CPU and system in general. Your server won’t have to generate the exact same dynamic page for 2 different users if there is no difference in content.

5. Use Nginx server as the origin for your CDN

We’ve already covered that Nginx is fantastic at serving static content. But what can you do to make your site even faster? Layer a CDN on top of the server to distribute your content across the globe. A content distribution network (CDN) will distribute your media, pictures, movies and other large objects to a network of thousands of servers across the globe. Depending on where a visitor is coming from to get to your site they’ll pull the media objects directly from the closest physical server location from the CDN instead of reaching all the way to your server. And for really intensive sites the Nginx server can deliver so much static content to a CDN that we’ve been able to feed a 100Gbps+ per second global site with just 2 back end Nginx servers.

These are the most popular configuration options for Nginx, if your server is starting to struggle with the loads you’re generating, or you’re getting too much traffic, it may be time to switch to Nginx. Selecting a fully managed hosting partner can make that transition a lot easier as all the configuration and prep work is taken care of. All that’s left for you to is to see your site performance improve, and the ability to serve tons more users from the same existing server.