11

I have installed varnish and fallowed the exact instruction for setting it up, however, it is not working as expected.

My /etc/default/varnish setup is:

DAEMON_OPTS="-a :80 \
             -T localhost:1234 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m"

My /etc/varnish/default.vlc setup is

backend default {
    .host = "localhost";
    .port = "8080";
}

My apache port.conf setup is:

NameVirtualHost 127.0.0.1:8080
Listen 127.0.0.1:8080

<IfModule ssl_module>
        Listen 443
</IfModule>

<IfModule mod_gnutls.c>
        Listen 443
</IfModule>

I am running ubuntu 15.04 with Apache 2.4.10. When I start varnish and check the process i get the fallowing:

0:00 /usr/sbin/varnishd -a :6081 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m

Seems like neither of the Listen address or the Management interface work as set in /etc/varnish/default.vcl. None of my virtual machines work as a result. How can I solve this ?

skonsoft
  • 1,786
  • 5
  • 22
  • 43
Lachezar Raychev
  • 2,113
  • 4
  • 24
  • 34

2 Answers2

33

Ok. Problem solved. First do

sudo grep -R 'ExecStart=/usr/sbin/varnishd' /etc/

so you can actually find the other place where daemon options for Varnish are set (in my case it was /etc/systemd/system/multi-user.target.wants/varnish.service). Open file in vim,nano or whatever and set "ExecStart" in that file as fallows:

-a :[same as /etc/default/varnish]80 -T localhost:[same as /etc/default/varnish]1234 -f [same as /etc/default/varnish ]/etc/varnish/default.vcl -S [same as /etc/default/varnish ]/etc/varnish/secret -s malloc,256m

Save and exit. After that do:

systemctl daemon-reload
systemctl restart varnish.service

And then we are done. Nothing like the official tutorial. Apparently it is old.

Full explanation of the problem here

Lachezar Raychev
  • 2,113
  • 4
  • 24
  • 34
4

You can change the varnish default port to 80 by using below steps:

  1. Open a file on path: sudo vim /lib/systemd/system/varnish.service
  2. Update your default: ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T :6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
  3. Run below commands: sudo systemctl daemon-reload sudo service varnish restart
danidemi
  • 4,404
  • 4
  • 34
  • 40
Mohd Zahid
  • 59
  • 4
  • /lib/systemd/system/varnish.service will be a system-owned file that is liable to be replaced when you upgrade the varnish package. Better is to use systemd's notion of 'overrides'. This is most easily accomplished using 'systemctl edit varnish.service'... you'll end up with a file /etc/systemd/system/overrides.d/varnish.service (IIRC). You can see the full config for a service using 'systemctl cat varnish.service', which shows which files make up a service. – Cameron Kerr Mar 05 '22 at 07:38