Reputation: 2742
I'm trying to configure Varnish Cache on my Ubuntu VPS. I've got it installed and have tried following setup guides and googling etc but my headers never seem to show that varnish is caching.
I am running a node server on port 3000, BUT, port 3000 is forwarding to port 80.. so i'm not exactly sure how this plays with varnish caching. Here are the relevant config options I have changed in varnish... and I haven't touched anything else.
File: /etc/varnish/default.vcl
backend default {
.host = "127.0.0.1";
.port = "3000";
}
File: /etc/default/varnish
DAEMON_OPTS="-a :80 \
-T localhost:80 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"
Upvotes: 2
Views: 1463
Reputation: 16666
If that is your entire VCL file, then there are multiple reasons why Varnish may not be caching. First, you should read about the default VCL.
The default VCL only caches GET and HEAD HTTP requests, and won't cache any page that has ANY cookies. Since most sites have some cookies now-a-days (such as Google Analytics tracking cookies), this means most sites won't be cached by the default VCL.
You should create your own VCL, specific to your site. For example, here is the documentation on removing cookies. You could remove cookies that don't affect the page. The reason that Varnish won't cache pages with cookies is to avoid caching pages with login cookies that may change the page contents (for example, logged in users see their names. You don't want the page cached and served to everyone).
Upvotes: 1