This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Setup Varnish Cache with VHosts (Ubuntu 14.04) 64bit
#1
Setup Varnish Cache with VHosts (Ubuntu 14.04) 64bit
[Image: Ubuntu-14.04_64bit-orange.svg?style=flat-square] [Image: Varnish-4.0.3-lightgrey.svg?style=flat-square] [Image: Sentora-1.0.0-blue.svg?style=flat-square] 
How to Setup Varnish Cache with VHosts
Learn how to install and configure Varnish 4 with Sentora and Virtual Hosts.

[Image: 90x60.png]
What's Varnish?
Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents. Varnish Cache is really, really fast. It typically speeds up delivery with a factor of 300 - 1000x, depending on your architecture.
read more at the varnish-cache.com about page or watch a quick video about varnish (2min)


System Requirements
Make sure you have the following:
  • Root Access.
  • 64bit OS (this guide is only for Ubuntu 14.04, but Varnish can be installed on other systems).
  • 1Gb of RAM is recommended.
more details on the official varnish-cache.com requirments page


Installation
Login to your server via SSH, make sure you are logged in as root.

Enter the following commands in the Terminal:
Code:
apt-get install apt-transport-https
curl https://repo.varnish-cache.org/GPG-key.txt | apt-key add -
echo "deb https://repo.varnish-cache.org/ubuntu/ trusty varnish-4.0" >> /etc/apt/sources.list.d/varnish-cache.list
apt-get update
apt-get install varnish


Setup Varnish
Installing was easy, not let's get our hands dirty and begin the fun part.
I will try to avoid server downtime, however keep in mind that you will need to restart apache at least once.

By default Varnish listens on port 6081 and uses the backend (apache) on port 8080;
In a production server we want Varnish to listen on port 80.


Test Drive Varnish (optional step) 
Let's just verify if Varnish is up and running, to do this we need to change the default.vcl file.
Open /etc/varnish/default.vcl on your favorite text editor and change the .port to 80 (should be line 18):
PHP Code:
# Default backend definition. Set this to point to your content server.
backend default {
 
   .host "127.0.0.1";
 
   #.port = "8080";
 
   .port "80";

see the default default.vcl file at the varnish GitHub Repository

Restart the Varnish service to apply the changes (execute the command on the terminal):
Code:
service varnish restart

Now open your website on port 6081 (http://domain.tld);
If Varnish is running correctly you should see your website, for further confirmation you can check the website headers (link to header-checker tool) for the  information Via => 1.1 varnish-v4.

Now that we tested it is working revert your default.vcl file back to.port 8080 (no need to restart varnish service right now).


Change Varnish Listening Port
First we will change the Varnish listen port from 6081 to 80;
Open /etc/varnish/default.vcl on your favorite text editor and change the DAEMON_OPTS="-a to 80 (~ line 40):
PHP Code:
#DAEMON_OPTS="-a :6081 \
DAEMON_OPTS="-a :80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m" 


Change Apache Port
Now we need to switch apache to port 8080;
Let's use the setso --set command that Sentora provides to easily change settings;
The first command changes the global apache port and the second one changes the Sentora Panel port.
Code:
setso --set apache_port 8080
setso --set sentora_port 8080


Launch Varnish Smile 
Login to Sentora Control Panel as zadmin and on Module Manager select Apache Config and switch the Apache Port from 80 to 8080 scroll to the end of the page and check the Force Update box to ensure the vhosts file will be updated on the next Daemon Run.

WARNING: After you Save the settings your server will be switched to port 8080, this means that every website in your server will not be accessibleTo minimize downtime we need to make sure that the following commands are done quickly.

Let's manually trigger the sentora Daemon and restart Varnish to apply the changes:
Code:
php -q /etc/sentora/panel/bin/daemon.php
service varnish restart
If everything went ok, without errors, Varnish should now be in front of your server (on all VHosts).
Verify your website (normal url, no port required) and check the website headers (link to header-checker tool) for the  information Via => 1.1 varnish-v4.




Last Comments
Not being hard to install and use, Varnish is a advanced tool and should be used with care.

Soon I will create a new guide about basic VCL scripting and how you can use your VCL files to cache only some websites on your Sentora Server.




If this guide helped you, please press the Thanks button and consider giving me some Positive Reputation using the Rate button.
I'll be happy  Wink
My Sentora Resources
[Module] Mail Quota Count | Vagrant Box with Sentora

[Image: vanguardly-logo-micro.png]
Graphic and Web Design. Development.
www.vanguardly.com


Reply
Thanks given by: Me.B , TGates , Ilia , Bobses
#2
RE: Setup Varnish Cache with VHosts (Ubuntu 14.04)
Hello,

Just installed !

Perfect just one thing this code come in /etc/default/varnish not in /etc/varnish/default.vcl
PHP Code:
#DAEMON_OPTS="-a :6081 \
DAEMON_OPTS="-a :80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m" 
Reply
Thanks given by:
#3
RE: Setup Varnish Cache with VHosts (Ubuntu 14.04)
(11-01-2015, 05:49 AM)Ilia Wrote: Hello,

Just installed !

Perfect just one thing this code come in /etc/default/varnish not in /etc/varnish/default.vcl
PHP Code:
#DAEMON_OPTS="-a :6081 \
DAEMON_OPTS="-a :80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m" 

Probably because you are on CentOS Smile
My Sentora Resources
[Module] Mail Quota Count | Vagrant Box with Sentora

[Image: vanguardly-logo-micro.png]
Graphic and Web Design. Development.
www.vanguardly.com


Reply
Thanks given by:
#4
RE: Setup Varnish Cache with VHosts (Ubuntu 14.04)
lol no on ubuntu !
Reply
Thanks given by:
#5
RE: Setup Varnish Cache with VHosts (Ubuntu 14.04)
(11-01-2015, 10:38 PM)Ilia Wrote: lol no on ubuntu !

Then update your profile with your correct server info... Angel
-TGates - Project Council

SEARCH the Forums or read the DOCUMENTATION before posting!
Support Sentora and Donate: HERE

Find my support or modules useful? Donate to TGates HERE
Developers and code testers needed!
Contact TGates for more information
Reply
Thanks given by:
#6
RE: Setup Varnish Cache with VHosts (Ubuntu 14.04)
Lol no sorry again !

My production server is on Zpanel Centos !

The one where i installed varnish is on Sentora Ubuntu !

To comeback to the subject as show in the github link of default.vcl it stops at line 40

and modificaton asked is in line 80.

lol
Reply
Thanks given by: TGates
#7
RE: Setup Varnish Cache with VHosts (Ubuntu 14.04)
(11-02-2015, 08:29 AM)Ilia Wrote: Lol no sorry again !

My production server is on Zpanel Centos !

The one where i installed varnish is on Sentora Ubuntu !

To comeback to the subject as show in the github link of default.vcl it stops at line 40

and modificaton asked is in line 80.

lol

Hmmm, that's the problem with 'external' repositories, they may have changed something Sad
-TGates - Project Council

SEARCH the Forums or read the DOCUMENTATION before posting!
Support Sentora and Donate: HERE

Find my support or modules useful? Donate to TGates HERE
Developers and code testers needed!
Contact TGates for more information
Reply
Thanks given by:
#8
RE: Setup Varnish Cache with VHosts (Ubuntu 14.04)
If you experience some flaws with your panel and certain modules you can skip de panel via varnish by adding this code in default.vcl:

Code:
sub vcl_recv {
   if (req.http.Host == "subdomain.domain.com") {
       return (pipe);
   }
}


No need to use if your panel is via SSL.
[Image: logo2.png]

My being on this forum is all personal and all is done here by me has nothing to with the company Web Improved I work for Smile
Reply
Thanks given by: apinto , TGates
#9
RE: Setup Varnish Cache with VHosts (Ubuntu 14.04)
bbspike nice touch!! Thank you!
My Sentora Resources
[Module] Mail Quota Count | Vagrant Box with Sentora

[Image: vanguardly-logo-micro.png]
Graphic and Web Design. Development.
www.vanguardly.com


Reply
Thanks given by:
#10
RE: Setup Varnish Cache with VHosts (Ubuntu 14.04)
I tried it but after setting it up I can't access the websites using varnish. Hmm. But I can access on port 8080. So I reverted it all back to defaults. Hmm. I'm using 32bit os because their website said it should work.
Reply
Thanks given by:


Possibly Related Threads…
Thread Author Replies Views Last Post
Upgrade to Ubuntu 16.04 from 14.04 HogensHero 8 30 ,342 07-18-2020, 03:13 AM
Last Post: dycott78
Ubuntu: How to Enable tls/ssl in proftpd Diablo925 2 12 ,837 04-21-2020, 03:35 AM
Last Post: iraqiboy90
Ubuntu 18.04 or 20.04 Kangarooo 1 6 ,950 03-20-2020, 11:39 AM
Last Post: Jettaman

Forum Jump:


Users browsing this thread: 1 Guest(s)