Recommended VPS Complete list of best VPS hosting providers.

VestaCP Configuration for Varnish Cache [Part 2]

This is the Part 2 article of my previous guide (Part 1) on how to setup Varnish Cache server to run with VestaCP. So if you have not read the Part 1, you better read that first.

Now let’s continue, shall we?

Stage 5 – Nginx Configuration

Step 1 – Go to /etc/nginx/conf.d/ directory and see if there is configuration file of your public IP:

cd /etc/nginx/conf.d
ls

2015-07-19_230500

Step 2 – Edit that .conf file. Replace xxx.xxx.xxx.xxx with your own actual public IP:

nano xxx.xxx.xxx.xxx.conf

You’ll see something like this:

2015-07-19_230820

Step 3 – Now change port :80 to :8082 as example below:

2015-07-19_230921

Save changes and exit the editor which in Nano it is Control+O then Control+X.

Step 4 – Also edit vesta.conf file located at /usr/local/vesta/conf/. Use your favorite text editor or in my situation I use Nano:

nano /usr/local/vesta/conf/vesta.conf

change PROXY_PORT from 80 to 8082

2015-07-19_231405

Save changes and exit (Control+O then Control+X).

Step 5 – Edit nginx.conf file for each Vesta CP user located at /home/user/conf/web. This step is quite not efficient if you have several Vesta CP users as you have to edit them all. In my example I will edit nginx.conf file for user admin:

nano /home/admin/conf/web/nginx.conf

Again, change port 80 to 8082 at the listen line. See example below:

2015-07-19_232126

Save changes and exit the editor (Control+O then Control+X).

Stage 6 – VestaCP Firewall Configuration

Open up your favorite web browser, login to your Vesta CP dashboard as admin then click the Firewall menu on top of the page.

2015-07-19_232534

Edit the /WEB section of the firewall

2015-07-19_232648

Now ad 8082 in the Port field and hit the green Save button.

2015-07-19_232813

Stage 7 – Give it a test

Step 1 – Before you are running for a test drive, you have to firstly restart Nginx and start Varnish Cache server:

service nginx restart
service varnish start

2015-07-19_233019

Step 2 – Next, you have to setup your domain to point to your server or you can simply edit your local hosts file in your PC.

Useful posts:

Step 3 – Now you can open up your favorite web browser (like Mozilla Firefox or Chrome) and access your website using your domain. Your website should now be displayed.

2015-07-19_233551

Stage 8 – More Varnish Configuration

I can see this stage is optional but you may also need this especially if you want to host complex scripts / CMS on production environment. What I’m talking here is tweaking Varnish. What I told you in Part 1 of this article is just editing default.vcl file defining where the backend is, plus there is also necessary config to forward real visitor’s IP addresses so your script and log files will record actual IP and not your server IP. For your information, there are several ready-to-use Varnish .vcl template to use with specific script like WordPress, Joomla or Drupal. Some what I can recommend are:

  1. https://github.com/pkhamre/wp-varnish
  2. https://github.com/mattiasgeniar/varnish-3.0-configuration-templates
  3. https://github.com/JohnMcLear/Wordpress-Varnish-VCL
  4. https://github.com/mattiasgeniar/varnish-4.0-configuration-templates

Feel free to Googling for more or come with your own configuration.

You can make sure if Varnish is really working on the right port (80) by doing curl:

curl -I http://domain.com

2015-07-20_004743

or by using web app like isvarnishworking.com:

2015-07-20_004905

if you see the X-Varnish line in the header respond that meaning Varnish is working correctly. With some advanced config in .vcl you can also get cache HIT or Missed status.

That’s all. Do not hesitate to leave comment below. Want to get faster update? Follow me on Twitter or subscribe using your email.

9 Comments

Add a Comment

Your email address will not be published. Required fields are marked *

Get more stuff like this
in your inbox

Subscribe and get interesting stuff plus faster updates to your email.