Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Varnish to run on port 80. Malfunction of DAEMON_OPTS set in /etc/default/varnish

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 ?

like image 242
Lachezar Raychev Avatar asked Jun 03 '15 09:06

Lachezar Raychev


2 Answers

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

like image 130
Lachezar Raychev Avatar answered Nov 18 '22 04:11

Lachezar Raychev


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
like image 26
Mohd Zahid Avatar answered Nov 18 '22 05:11

Mohd Zahid