NGINX optimized webserver for WordPress, with Varnish!


Read our top-level overview on how high traffic Wordpress websites can benefit from using an NGiNX and Varnish combo, instead of the traditional LAMP Stack

Does your WordPress site get a lot of traffic?

No. I mean a LOT of traffic…

We’re talking traffic that fully saturates a 1Gbps port and services hundreds of TB of http traffic per month, complete with heavy dynamic pages, plugins, and thousands of concurrent users clicking around.

Now what if I told you that you could host a Godzilla WordPress site like the above on a single VPS with no more than 8GB of RAM?

While this sounds like a dream for many webmasters, suffering from sluggish cPanel, Plesk, and Apache based hosting – imagine that this is now available for even those on a strict budget!

That’s because instead of working hard, we can now work smart with NGINX and Varnish!

Stop throwing your money at hardware and optimise your WordPress site properly. By adding NGiNX and Varnish into your webstack, you will be able to withstand tremendous traffic, even with heavy plugin ridden WordPress sites.

No latency, no downtime, and real-time performance.

Supercharge the performance of your WordPress website with NGiNX and Varnish caching

Getting that neck-snapping response time on WordPress is easy to accomplish if you use the right tools. We suggest building your custom WordPress server using a base of CentOS 7 x64.

And instead of using cPanel and Apache as nearly everyone uses today, we say “hello” to Varnish, NGINX, PHP-FPM, and PerconaSQL.

Of course, just slapping some software together doesn’t make something quick nor reliable.

You need to know what to tweak under what circumstances, in order to build a personalised server, built precisely your WordPress website.

Thankfully there are plenty of tutorials on how to do this. But this post is not one of them. It’s more of a top-level overview of the NGiNX/Varnish webstack for WordPress, the benefits, and who it is for.

Let’s read on!

Why choose NGiNX instead of Apache for WordPress?

In a traditional hosting server, whether shared or dedicated, when someone visits your website an Apache process handles each individual click that a viewer makes, sending requests to the MySQL database server in real-time.

Each and every click results in queries being generated against the database, and of course each and every click, also results in your WordPress website being rendered by Apache & PHP, and sent to your viewers’ browser.

Of course, some can say that “APC can cache just fine”, or “we use file caching, we don’t need anything else!” – while both are respectable statements, times have changed and caching is not an application level affair any longer.

Heavy websites must be cached externally, this means, outside the application itself.

It is perfectly acceptable for the web application to be aware of the caching, so that hit counters and the like are kept up to date, however the actual ‘caching’ process must be external to the webserver stack.

We use Varnish, which is a separate server completely isolated from the ‘webserver’ stack. It works to completely ‘cache’ a website in RAM Memory so that each click a visitor makes does not result in any unnecessary queries, while at the same time fully adhering to your requirements for cache control.

For example, let’s say that you have some pages, such as your home page, which you wish to have a cache of 3 minutes, but some other pages should be cached for 10 or 15 minutes, this is all easy to control using our Varnish WordPress plugin and Varnish VCL’s.

Further enhancing the logic of ‘external caching’, is that with Varnish caching your website, you can serve stale content. This is very similar in concept to CDN. In fact, most CDN’s are actually powered by Varnish anyway.

What does this mean:

Your webserver stack can go down for many reasons.

  • Maybe you had a MySQL database crash
  • Maybe you have a loop in a script
  • Maybe you have a broken connection script
  • Maybe you are or even missing files you accidentally erased

Varnish comes to the rescue here.

Varnish will detect that your webserver stack is inoperable and will immediately and automatically start serving ‘stale’ content which it had cached previously during normal operation.

What’s the result for you?

None of your front-end visitors will ever experience any website errors or ‘500’ messages while browsing.

Database (Percona Server with XtraDB) 

WordPress is very database intensive, and even though we are caching your website with Varnish, and requests are served in real-time, we still extend the enhancement over the ‘base webserver’ package by replacing MySQL with Percona.

Percona is faster when dealing with InnoDB databases, and this is exactly what we run WordPress databases under in large installations and/or deployments with extensive database activity, e.g. a news portal website with >10K posts.

Webserver (NGINX)

Serving traffic at this pace is possible with Apache, but it will require a lot more server resources, especially RAM!

This is why for high traffic WordPress websites, we only use NGiNX for our custom build webserver solutions.

NGINX was developed by Igor Sysoev, and was battle-tested for years hosting site such as Yandex, VKontakte, Rambler, Mail.ru.

NGINX is fully compatible with WordPress, and provides all the functionality you need to ‘set it and forget it’ without experiencing downtime and latency. And guess what? WordPress.com itself, uses NGINX! 

Apache is like Microsoft Word, it has a million options but you only need six. Nginx does those six things, and it does five of them 50 times faster than Apache.
— Chris Lea on nginx and WordPress

NGiNX shines because it is an event based webserver, whereas Apache is a process based server. The difference between the two systems is staggering under any semblance of load borne by heavy traffic. 

500 simultaneous connections would probably only cause Nginx to use a few megabytes of RAM whereas Apache would probably consume hundreds of megabytes (if it could do it at all).

Is WordPress difficult to manage if you use NGiNX and Varnish?

Its nice to know, that an advanced NGiNX webstack for WordPress can be delivered with a fully functional control panel thanks to ISPConfig. And it’s also free, good to know.

This gives you all the functionality you probably already use within cPanel like the ability to:

  • Create domains with point and click
  • Create mail accounts
  • Reset passwords
  • Access webmail
  • Execute backups of domains and mailboxes
  • Manage subdomains,
  • And if needed, provide reseller accounts for your advanced clients.

Why choose managed hosting for your NGiNX optimised WordPress setup

While it is possible for you to organise all of this on your own, we do not suggest experimenting on mission-critical production websites. The stakes are too high and there is little room for error when working on high-traffic WordPress sites.

By choosing the right managed hosting provider you can get a full end to end support for your entire server, and the implementation of WordPress on your server as it relates to Caching, Databases, Webserver stack, Email, Backups, and PHP specifics.

What’s the migration process look like?

Discovery Call

We usually recommend that customers follow a 30-minute initial discovery call over Skype with the implementation team to carry out a pre-migration audit on your setup. Large-scale migrations can be tricky so it’s important to spend the time to observe and plan before acting.

Migration

The best-managed WordPress hosting providers will make sure that during the migration, the implementation specialist debugs any and all problems associated with the webserver change to NGINX, databases to InnoDB if needed, etc.

Validation 

Once this procedure is completed, sometimes a validation session of 30 minutes is organized to confirm proper operation of the website, databases, cron jobs, emails, forms, caching, and backup systems.

DNS Change

After everything’s validated to work perfect on the new setup you need to organize the specifics of the DNS configuration so that your website can be switched to the new server.

Synchronisation

The final step of this procedure is usually to synchronize files and database tables so that when your migration is completed, you have not lost a single post or comment on your WordPress website.

Post-Migration Monitoring

After the implementation is complete, monitoring is established on your server, and on your application. At EuroVPS, we use a combination of Paessler PRTG monitoring system to observe the real-time status of the server and New Relic to monitor the status of your website in real-time.

Both together provide you with a transparency into your server’s inner workings and you can rest assured that you won’t wake up one morning to a downtime due to a flood of traffic, as we’ll know well in advance when the time to upgrade the server is – based on real metrics.

Want to work together?

We have plenty of experience when it comes to optimizing WordPress websites for site speed and dealing with tsunami traffic spikes. We pride ourselves on our uptime and our rapid response rate, and our customer service team is available around the clock to save you time so you can focus on the important things in life.