1

I seem to be having an issue with varnish. It's nothing major but I'm struggling to find where I may be going wrong.

Basically, varnish is set to run on port 6081 which it does; however. I've tried editing the /etc/default/varnish config and changing the daemon_opts to 80, and even commented-everything out from the file, but varnish seems to still run on 6081.

So either its not using the /etc/default/varnish config, and getting its settings elsewhere, or /etc/default/varnish isn't making any difference.

My question is does anyone know what config file it may be using to get its settings, or perhaps how I can force it to use a config? Thanks.

1
  • Post your varnish config
    – Wesley
    Dec 18, 2015 at 2:29

2 Answers 2

1

Figured a fix as it's a bug with varnish. The remainder of this post is an edited version of this article: http://deshack.net/how-to-varnish-listen-port-80-systemd/


Basically, /etc/default/varnish is only read by the /etc/init.d/varnish script, not by the systemd init script (/lib/systemd/system/varnish.service).

We can override the systemd init script of varnish and change something.

# cp /lib/systemd/system/varnish.service /etc/systemd/system/
# nano /etc/systemd/system/varnish.service

We come up with something like this:

[Unit]
Description=Varnish HTTP accelerator

[Service]
Type=forking
LimitNOFILE=131072
LimitMEMLOCK=82000
ExecStartPre=/usr/sbin/varnishd -C -f /etc/varnish/default.vcl
ExecStart=/usr/sbin/varnishd -a :6081 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
ExecReload=/usr/share/varnish/reload-vcl

[Install]
WantedBy=multi-user.target


ExecStart=/usr/sbin/varnishd -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m

Then use either,

# sudo service varnish restart 

or

# systemctl reload varnish.service
1
  • Next time don't steal content. Add attribution.
    – Wesley
    Dec 18, 2015 at 2:36
0

Be sure you used right DAEMON_OPTS line. Default Varnish config has 4 examples of DAEMON_OPTS configuration (Alternative 1, Minimal configuration; Alternative 2, Configuration with VCL; etc). If you uncommented couple of them, only last uncommented DAEMON_OPTS line will be applied.

Example:

## Alternative 2, Configuration with VCL
#
# Listen on port 6081, administration on localhost:6082, and forward to
# one content server selected by the vcl file, based on the request.
# Use a 256MB memory based cache.
#
DAEMON_OPTS="-a :80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl.v4 \
             -S /etc/varnish/secret \
             -s malloc,256m"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .