How can i configure w3 total cache, fastCGI, and optimize nginx for best performance on Ubuntu 14.04 x32 $10

Posted April 11, 2017 9.2k views

Hi, all
My blog is Actually i am not good with managing servers and i need help in configuring w3 total cache, fastCGI cache and Lowest TTFB on my VPS.

Method i followed

I have followed given below methods in order to configure VPS


Configuration i have

Ubuntu 14.04 x32 $10

Issues i am facing

  1. when i am installing w3 total cache plugin on my wordpress, the website starts showing 502 bad gateway. dont know how to resolve this.

What help i need

  1. Complete step by step guide to configure w3 total cache for best performance along with minify, and static content caching. i don’t have CDN

  2. Nginx optimization as per my VPS configuration given above

  3. FastCGI caching configuration

  4. Configuration for best TTFB

Thanks in advance.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers


If you’re using NGINX FastCGI Caching, there’s very little that W3TC or WP Super Cache will be able to offer you, even if you store FastCGI Cache to disk instead of RAM. Minification is about the only thing FastCGI cache doesn’t handle, but Pagespeed** does.

Essentially, these plugins store static pages as a means of caching your site – FastCGI Cache does the same thing. The difference between the two is NGINX is managing the FastCGI Cache whereas with a plugin, your PHP code is handling it. NGINX is going to handle it much faster, though there’s a downside.

The downside is that, unlike W3TC and WPSC, FastCGI Cache does not auto-purge when you add a new page, post a new post, update pages/posts, etc. You have to clear it manually.

There is a FastCGI Cache helper plugin, but it relies on a module that requires that you compile NGINX from source and build that module in. Said module also doesn’t work with the latest version of NGINX, so you’d have to rely on a slightly dated version of NGINX until the module is updated (which doesn’t appear as if it’ll be anytime soon).

As far as W3TC goes, there’s really not a one-shot configuration that “just works.”

When you step in to minification, you step in to an area that is going to require that you’re capable of troubleshooting, especially when using auto-minify.

Auto-Minify just doesn’t work well when there’s a ton of JS files as not all JS files follow the same spec in terms of coding, thus not all will minify as expected. You may have 20-30 JS files and 10-15 of those will work as expected and you’ll have to troubleshoot why you can’t minify the last 5-15. Doing so may result in odd looking pages, missing content, etc.

** Pagespeed, like the FastCGI Cache Purge module, requires that you build NGINX from source. It’s not part of the NGINX Core.

All that being said, I can help you with one aspect of getting NGINX setup. I wrote an auto-installer which installs the latest Mainline version of NGINX and comes stock with a pre-optimized configuration.

It builds NGINX from source and includes pagespeed so you can tinker with it.

There’s auto-installers for NGINX, PHP 5.6/7.0/7.1, and MariaDB. I’d recommend running this on a clean Droplet (i.e. freshly deployed, nothing installed by you).

cd /opt \
&& git clone
&& cd installers/nginx \
&& chmod +x \
&& ./

That’ll auto install NGINX. You can then change over to the other directories to auto-install MariaDB and PHP using the same commands.


cd installers/mariadb/10.x \
&& chmod +x \
&& ./
cd installers/php/7.1 \
&& chmod +x
&& ./

You’ll still need to configure server blocks, your sites, setup them up, etc, though these offer a way to get the server setup. Security isn’t a factor here, so you’ll need to properly secure your server, etc. I am working on a full LEMP Stack installer, though it’ll be a little bit before it’s ready for production use.

  • Thanks a lot for your detailed answer bro. As you said that FastCGI cache cannot clear the cache automatically when a page, post or anything is updated (which is an important thing). I would like to know whether Apache would work better in terms of performance and TTFB? i dont have any problem in switching over to Apache from Nginx.

    If “YES” then, what version of PHP, Apache and other tools i shall install *to get the best compatibility and performance on my wordpress website? Is there any specific configuration for *Apache that will get me the best performance?

    Thanks in advance… :)

    • @sourabhv1989

      When it comes to Apache, depending on traffic and configuration, you’ll most likely end up using more CPU/RAM than you would with NGINX/PHP-FPM.

      This is due to the fact that with Apache, config changes (i.e. .htaccess) are dynamic. You can make a change to the .htaccess file without restarting Apache. You can not make a change to the NGINX config without reloading/restarting NGINX.

      When it comes down to metrics and performance, my experience tells me NGINX wins and I’ve been working on the sysadmin side for about 15 years.

      As far as TTFB, NGINX and Apache are not the only factors at play and TTFB is only one of a dozen+ metrics used to gauge site speed.

      You could very have a 10ms TTFB, but a 3 minute page load time due to poor optimization – in such a case, TTFB is irrelevant – you’ve got bigger issues.

      TTFB is a measure of responsiveness – a measure of how quick your site responds to the request. Caching does indeed help as static pages are served faster, in most all cases, than those they are dynamically generated. But there’s also times where you may have blocking occurring, i.e. something blocking the request (something is waiting to load, doesn’t load, can’t load, etc) which will cause the TTFB to rise.

      If you’re TTFB is somewhere in the 10-50ms range, or slightly over, you’d be micro-optimizing (which is often a bad thing, unless there’s a reason).

    • Sourabh, how did you end up optimizing this setup, surprising, i am running into the same issues here. Thx.

im not an expert, but as far i think, you should skip w3tc when you are using FastCGI. the reason for this is, w3tc store cached files in disk which is the slowest part of your setup. on the other hand, you can setup FastCGI to store cache files in memory (var/run/) which is alone pretty fast. having properly configured FastCGI is enough alone to make your site blazing fast. W3tc could even degrade performance in this case.

as for optimizing Nginx, follow this guide

and this one for setting up FastCGI

by Jesin A
Here's how to setup FastCGI caching with Nginx on your VPS.

Hi @sourabhv1989

You might want to add HTTPS, so you can deliver content over HTTP/2, which delivers through one tunnel instead of creating a connection for each object (image, css, js, etc) on the server.

by Mitchell Anicas
In this tutorial, we will show you how to use Let's Encrypt to obtain a free SSL certificate and use it with Nginx on Ubuntu 14.04. We will also show you how to automatically renew your SSL certificate. If you're running a different web server, simply follow your web server's documentation to learn how to use the certificate with your setup.