LANNN – extra speed with using Varnish in front of Nginx and Node.js

This post will show you how to gain extra speed with Varnish going hand in hand with NginX and Node.js on AWS EC2 instance. We will throw varnish into the game to make everything run much faster.

This article is continuation of AWS – Nginx Node.js MongoDB series. And it is based upon everything we have shown so far. Although you can use it on its own it is highly recommended that you read other posts as for some system settings it is assumed you already running nginx and node.js or perhaps php-fpm. If you however looking for installation guide just dive into it without further delay.

Varnish installation on CentOS

First step is to get Varnish up and running so lets go ahead and do it

Now we can start varnish service

User web browser to check if  http://your_host:6081/ displays the same content that is visible on http://your_host/ or http://your_host:80/ Note: You can also start Varnish manually specifying main port . It is however not required if yo you are using service command.

Or to make it listen on default port

To make sure it starts after instance reboot execute

Varnish configuration

Below you will find different types of configurations we are suggesting based on hundreds pages of documentation and  other blogs supported with tens of tests. Just pick which one is suitable for you or go through all of them get broader understanding of what you can do with Varnish.

Varnish basic configuration for NginX

Edit   /etc/nginx/sites-enabled/default changing port your server is listening to 8080 for each server directive you are using in default config file

Now change default port varnish listens on, which is  6081 edit varnish main config file

replace the following line


And now lets focus on varnish default config file. Backup it up (optional) and edit

Once opened, replace its content with below settings

Restart both services

Varnish configuration for Node.JS

(coming soon….)

Varnish configuration for Node.JS  with support of web sockets

(coming soon….)

Varnish configuration for WordPress hosted EC2 instance

This is very simple WordPress configuration. Open default.vcl  file

Replace your vcl file content with below settings.

 Some usefull sources

This post wouldn’t be possible without those articles so great thank you to all of those guys


Marek (admin)

Freelance developer, IT enthusiast, blogger with entrepreneurial spirit and passion for making games