2

I have a WordPress site with gunicorn and varnish running on an AWS instance.

This morning, the website gave a "502 Bad Gateway nginx" error.

Upon investigation, it looks like the varnish.service port was:

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

According to some notes, the port needs to be 80 and not 6081. Changing the port to 80 fixed the nginx error.

This issue seems to happen about once a year where the varnish.service port suddenly changes by itself and someone has to manually change the port back to 80.

So my question is - why would varnish.service suddenly change its port? As far as I know, there were no updates or changes anywhere.

Chris
  • 500
  • 6
  • 25

1 Answers1

1

It depends on what file you're editing.

Make sure you're editing /etc/systemd/system/varnish.service. If that file isn't there, just run the following command:

sudo cp /lib/systemd/system/varnish.service /etc/systemd/system/

When you're done editing the port, just run the following 2 commands:

sudo systemctl daemon-reload
sudo systemctl restart

See https://www.varnish-software.com/developers/tutorials/installing-varnish-ubuntu/#systemd-configuration for a detailed tutorial.

Thijs Feryn
  • 3,982
  • 1
  • 5
  • 10
  • Thanks - the file `varnish.service` file is there. It's just that out of the blue one day, the port changed from `6081` to `80`. Reverting it back to `6081` fixes the problem - but why would it have randomly changed to `80` in the first place? – Chris Aug 24 '22 at 22:03