How to Install and configure Varnish in Ubuntu 18.04 nginx server?

March 23, 2019 1.6k views
Nginx Caching WordPress LEMP PHP IPv6 MySQL

I already installed NGINX, PHP-FPM, MYSQL and Wordpress in Ubuntu 18.04 . Also, I have Let’s Encrypt SSL .
Even i use Cloudflare CDN on the top of my domain.

And to improve my site load performance even more, now i want to install Varnish on my NGINX server. How can i do it? And whether it’ll be worth it or not?

Thanks in advance! :)

2 Answers

Thanks Petar for giving me such a detailed useful answer! :)

Since you already have CloudFlare in front of your web site, Varnish likely won’t provide a significant performance boost, since CF already offloads all static assets across their CDN edges and delivers them to your end users (in almost the same way as DigitalOcean Spaces would). It’d make sense to install Varnish if you had a high traffic web site with several thousand visitors per day, since it comes with a lot of advanced features that could help you in that case. If I understand correctly, you have a single droplet with the usual LEMP stack with CloudFlare on top of it, which is more than enough for your current needs.

Instead, what I recommend you install instead is Redis. Although PHP 7 & PHP-FPM in Ubuntu 18.04 come with sensible defaults when it comes to OP cache and performance in general, adding Redis to your stack can provide an additional speed bump. Just make sure you configure Redis as a non-persistent cache and assign at least 256 MB of RAM for it (you don’t want it to hit the disk) and then install Redis Object Cache plugin for WordPress so that your WP instance can talk to Redis cache and vice versa. Going through Redis & WordPress documentation should be enough for you to figure out how to do this, and if you do get stuck, a few Google searches will likely point you in the right direction.

Also, keep in mind that Ubuntu 18.04 and newer ships with MySQL 8 which tends to use more system resources than previous versions by default. In my experience, the default configuration isn’t the most optimal since version 8 is still relatively new and there aren’t many production scenarios we could refer to for best practices yet, so another thing I’d suggest you try is the famous MySQL Tuner script after a few days of MySQL running on your droplet. It will analyze the overall performance of your MySQL instance and will provide performance optimization suggestions you can implement right away to further optimize MySQL on your droplet.

Hope this helps!

Have another answer? Share your knowledge.