VestaCP Configuration for Varnish Cache [Part 2]
#howto ,#tutorial #VPS – VestaCP Configuration for Varnish Cache [Part 2] – This tutorial explains step by step guide (with pics) about 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
Step 2 – Edit that .conf file. Replace xxx.xxx.xxx.xxx with your own actual public IP:
You’ll see something like this:
Step 3 – Now change port :80 to :8082 as example below:
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:
change PROXY_PORT from 80 to 8082
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:
Again, change port 80 to 8082 at the listen line. See example below:
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.
Edit the /WEB section of the firewall
Now ad 8082 in the Port field and hit the green Save button.
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
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.
- List of free DNS hosting providers
- How to pointing domain to your VPS using free DNS manager
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.
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:
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
or by using web app like isvarnishworking.com:
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.
This post VestaCP Configuration for Varnish Cache [Part 2] is part of ServerMom.