I have been trying to install Varnish on ubuntu 18.04. I have used this article https://hostadvice.com/how-to/how-to-setup-varnish-http-cache-on-an-ubuntu-18-04-vps-or-dedicated-server/,
after I run the command curl -I http://localhost
but I get the error curl: (7) Failed to connect to localhost port 80: Connection refused
.
/etc/default/varnish
DAEMON_OPTS="-a :80
-T localhost:6082
-f /etc/varnish/default.vcl
-S /etc/varnish/secret
-s malloc,256m
/etc/varnish/default.vcl
backend default {
.host = "127.0.0.1";
.port = "80";
Results of curl -I http://localhost:8080
curl -I http://localhost:8080
HTTP/1.1 200 OK
Server: Apache/2.4.25 (Debian)
ETag: "29cd-56dff9168052e"
Accept-Ranges: bytes
Content-Length: 10701
Vary: Accept-Encoding
Content-Type: text/html
the output of sudo service varnich restart
is Failed to restart varnich.service: Unit varnich.service not found.
how can I resolve this problem ?
2
Answers
Update
Based on the new info the problem is the Varnish VCL config. It’s missing alot of information.
Here is an example VCL modified according to your setup
Replace the contents in your default.vcl with this and then restart Varnish.
There isn’t any service listening on
localhost:80
Double check that Varnish is running
If Varnish is running then you have to check the Varnish config
Should print something like
Where the key is
-a :80
Also make sure that your
Varnish service
have the same port configThen try to restart Varnish
Tip
You can verify that Apache is working by curling on port
8080
Your configuration is faulty to begin with.
In the DAEMON_OPTS you’ve set varnish to listen on port 80, while in the default.vcl you’re configuring a backend for varnish which should listen on the same 80 port.
This will lead into a neverending loop.
In your case, you want to set apache as a backend for varnish. As you’ve configured apache to run on port 8080, you’ll need to reflect this in the default.vcl
Do a
sudo service varnish restart
afterwards.