5

After installing Varnish via sudo apt-get update && sudo apt-get install varnish, and then:

sudo sed -i 's/Listen 80/Listen 8080/g' /etc/apache2/ports.conf
sudo sed -i 's/\*\:80/\*\:8080/g' /etc/apache2/sites-available/000-default.conf
sudo sed -i 's/DAEMON_OPTS="-a \:6081 \\/DAEMON_OPTS="-a \:80 \\/g' /etc/default/varnish
sudo systemctl restart apache2.service && sudo service varnish restart 

If I go to a website that worked before this installation, I get:

ERR_CONNECTION_REFUSED.

This is wired because the backend default in /etc/varnish/default.vcl is .port = "8080";.

  • When executing either varnishncsa or varnishlog brings no output in Bash.

My question:

Why would this happen? Varnish is on port 80, Apache on 8080... What else could go wrong?

Notes:

I also tried to change 80 to 8080 in all of my website conf files. Besides the fact it didn't help, I already realized this was a mistake (the websites are accessed through port 80, hence in contrast to 000-default.conf their conf file port shouldn't change to 8080).

5
  • Let me see if I understand. You want Varnish to run on port 80, and Apache to run on port 8080. This means you need to update Apache to listen to port :8080, and nothing on port 80. Double-check your config to make sure this is the case. Your Varnish setup looks fine. Are you getting ECONNREFUSED on port 80 or 8080? Does it work if you connect to port 6081? Also, if you're running on 15.04 or newer, look here as well.
    – Kaz Wolfe
    May 10, 2017 at 17:59
  • Hi Kaz! I updated Apache to 8080 in both ports.conf and 000-default.conf, I really double checked my config at least three times (all 3 files, that includes /etc/default/varnish). Regarding ECONNREFUSED, it happens both on port 80 and 8080 (I now tested that in the browser with my domain judith-law.co.il).
    – user423047
    May 10, 2017 at 18:19
  • I think I didn't understand your last question regarding port 6081: AFAIK when Varnish is on port 6081 it has no effect on the websites.
    – user423047
    May 10, 2017 at 18:21
  • Alright, see my answer, it should explain the port 6081 issue a bit better. If not, let me know and we can drop into a chatroom where I can help a bit more reliably with this issue.
    – Kaz Wolfe
    May 10, 2017 at 18:22
  • Kaz, I meant to ask with all sincerity why would it matter if Varnish works when I check it on port 6081, that is, the usual effect of Varnish will be given on port 80... In any case, what is the right way to check if it's working on port 6081?
    – user423047
    May 10, 2017 at 19:12

1 Answer 1

4

ERR_CONNECTION_REFUSED usually means that a port is blocked by a firewall, or there is nothing listening on that port.

If you're running on Ubuntu 15.04 or higher, the switch to systemd changed how Varnish reads configurations. Namely, it will ignore /etc/default/varnish and instead read the service file at /etc/systemd/system/varnish.service. Therefore, your Varnish server is probably running on the default port 6081.

To fix this, you'll need to override the systemd config. Run these commands:

sudo mkdir -p /etc/systemd/system/varnish.service.d
sudo nano /etc/systemd/system/varnish.service.d/customexec.conf

This will create a custom execution file for Varnish's service, which will contain your custom settings. In this file, make sure the contents are:

[Service]
ExecStart=
ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m

Make any changes to the config that you want to change, and then save the file with Ctrl+X.

Reload the systemd service cache by running this command:

sudo systemctl daemon-reload

When that command is done, restart the Varnish service:

sudo systemctl restart varnish.service

Make sure your firewall allows port 80 through, and you should be good to go.

As usual, this solution also assumes Apache is using port 8080 for everything -- there should be no binds to port 80 anywhere in the Apache config. Double-check this to make sure it's the case. If it is, one of Apache or Varnish will fail to start or work.

(source)

0

You must log in to answer this question.