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 4.x for CentOS 6.x
#1
Setup Varnish 4.x for CentOS 6.x
This tutorial is strictly for Varnish 4.x, Sentora 1.0.x, and CentOS 6.x.

Installation

Log into your server via ssh gaining root access.

IMPORTANT - Make a backup of of your vhosts file.

Code:
cp /etc/zpanel/configs/apache/httpd-vhosts.conf /etc/zpanel/configs/apache/httpd-vhosts.bak.conf

Get the latest version of Varnish from their repositories:

Code:
cat << EOF >> /etc/yum.repos.d/varnish.repo
[varnish]
name=Varnish for Enterprise Linux 6
baseurl=https://repo.varnish-cache.org/redhat/varnish-4.0/el6/
enabled=1
gpgkey=https://repo.varnish-cache.org/GPG-key.txt
gpgcheck=1
EOF

Then install Varnish

Code:
yum install -y varnish


Configure Varnish

Using your favorite editor open /etc/sysconfig/varnish and change "VARNISH_LISTEN_PORT" to

Code:
VARNISH_LISTEN_PORT=80

Using your favorite editor open /etc/varnish/default.vcl and make sure line 16-18 states

Code:
 
backend default {
   .host = "127.0.0.1";
   .port = "8080";


Configure Sentora

set your apache port

Code:
setso --set apache_port 8080

set your sentora port

Code:
setso --set sentora_port 8080

Go to your sentora administration panel to admin --> Module Admin --> Apache Config and set "Apache Port" to "8080".  Tick the "Force Update" box and click on "Save Changes"

restart the apache server

Code:
service httpd restart

start / restart Varnish

Code:
service varnish restart

If all goes well both should restart with no issue and Varnish is running in the front of your apache server.

If for some reason the varnish service is not starting try to start it again. If it still does not start and you think there my be a syntax error somewhere you can run the varnish debug command to see where your error is.

Code:
varnishd -C -f /etc/varnish/default.vcl


To verify Varnish is working correctly

Going back to you root login via ssh type in the command below replacing 127.0.0.1 with one of your websites.

Code:
curl -I http://127.0.0.1/

You should get back a response that looks similar to this:

HTTP/1.1 200 OK
Date: Tue, 29 Mar 2016 22:43:18 GMT
Server: Apache
Vary: Accept-Encoding,Cookie
Cache-Control: max-age=3, must-revalidate
WP-Super-Cache: Served supercache file from PHP
Content-Type: text/html; charset=UTF-8
X-Varnish: 65560
Age: 3
Via: 1.1 varnish-v4
Connection: keep-alive


Two flags  to that let you know Varnish is working correctly:

X-Varnish: 16
Via: 1.1 varnish-v4


In case something goes wrong


Remove Varnish completely

Code:
yum erase varnish

Restore your vhosts file

Code:
cp /etc/zpanel/configs/apache/httpd-vhosts.bak.conf /etc/zpanel/configs/apache/httpd-vhosts.conf

Set your apache port back to 80

Code:
setso --set apache_port 80

set your sentora port back to 80

Code:
setso --set sentora_port 80

Restart the apache server

Code:
service httpd restart
Reply
Thanks given by: Ron-e
#2
RE: Setup Varnish 4.x for CentOS 6.x
If you have more than an IP you can set varnish side by side with sentora each on own IP. So customers can either for example use cdn.domain.com thru varnish ( with extensive and heavy caching ) or use direct access.

M B
No support using PM (Auto adding to IGNORE list!), use the forum. 
How to ask

200$ free to start your VPS 60 days credit
Reply
Thanks given by:


Possibly Related Threads…
Thread Author Replies Views Last Post
Fail2ban for Sentora (Centos 7) bbspike 14 48 ,677 01-14-2020, 07:32 AM
Last Post: Vedran B
[How To] Update from PHP v5.4.16 to v5.6.31 (Includes suhosin patch) [CentOS] betatester3.0 5 19 ,358 03-18-2019, 01:23 AM
Last Post: BigBang
Ubuntu: How to setup TLS on postfix and dovecot Diablo925 28 116 ,116 02-15-2018, 08:46 PM
Last Post: duane

Forum Jump:


Users browsing this thread: 1 Guest(s)