Manual talk:Varnish caching

if-none-match support added?
Given this changeset purportedly added support, should we remove the section on "if-none-match" in vcl_recv? GreenReaper 04:14, 9 August 2010 (UTC)

The advice here, helped, but I had a lingering problem with 127.0.0.1 in my recent changes. adding

remove req.http.X-Forwarded-For; set   req.http.X-Forwarded-For = client.ip;

to my vcl_recv seemed to do the trick. Cariaso 18:55, 9 July 2011 (UTC)

Varnish 3.0
The Varnish 3.0 package on Ubuntu installs the initial config file under /etc/default/varnish. It also requires you to explicitly state "return" - such as:

return(lookup);

More info and a few other things (like "purge_url" is now "ban_url"):

Upgrading from Varnish 2.1 to 3.0

Varnish 3.0 config file example?
Hi, where can I get a *good* example of a varnish 3.0 configuration file? The one on the manual did not helped me. Another question: what should one insert/replace for "^images.example.org$"? A subdomain of my domain where all images are stored?

Thank you and best regards, --Mrnett1974 17:15, 21 January 2012 (UTC)


 * The "images" server only applies to a site where the content is split among multiple webservers on different domains, with (typically) the most obsolete hardware (P4, Celeron...) and small, low-powered server software (lighttpd, nginx) used to serve images and static content while more powerful servers handle the database, Apache and dynamic wiki content. A site using a content delivery network would need this - in Wikimedia's case, the image servers are on 'upload.wikimedia.org' and the wiki is on '*.wikipedia.org'. If your site doesn't need it (and many single-server sites do not), don't use it. --Carlb (talk) 21:17, 24 February 2012 (UTC)

Purge updated pages with Varnish 2.x
I'm using MW 1.19.0 and Varnish 2.1.5. Automatic purging of updated pages did not work until I applied the patch described in  this post. For your convenience, here's my patch adapted from the one in the above post:

Varnish 4 purging
I don't think the vcl_hit/vcl_miss is necessary the official documentation describes a new way to do it using. Daniel Friesen (Dantman) (talk) 01:56, 1 March 2015 (UTC)

Varnish 4.x not working & mobile example?
Hi! I refer to my question on serverfault.com (where i asked because i thought it was an error from me :)), but it seems, that the example Varnish 4.x configuration doesn't work and has an error. After uncommenting this directive:

pages are cached by varnish. Before that the backend delivered the actual page. Now the question: Why was this directive added? What should it do?

And another question: Can anyone give an example how to handle requests from mobile devices, if MobileFrontend is installed? I couldn't find any examples (and not the implementation of the wmf?)? Best, Florianschmidtwelzow (talk) 23:37, 10 May 2015 (UTC)

purging does not work with Varnish 4
https://www.mediawiki.org/wiki/Manual:Varnish_caching#Configuring_Varnish_4.x

If you use the above setting before 8/17/2015. The purging function does not work at all.

The correct configue should be           return(purge);}         not return hash in 4.x version. (Under # This uses the ACL action called "purge". Basically if a request to.......)

I have changed the Manual and Now the new setting is correct. --Zoglun (talk) 20:52, 17 August 2015 (UTC)

Is it possible to deliver stale content to login user with Varnish?
Hello,

I am trying to server anonymous cached page to login user when back-end down.

So I have read this page Manual:Varnish_caching and set up Varnish fro Mediawiki successfully. However the back end were not very stable, especially when high traffic comming in suddenly. Based on this article: https://info.varnish-software.com/blog/configure-saint-mode-grace-varnish-4.1, I got the grace mode work for anonymous user. However, due to the fact that login user will pass to back-end. I can't server anonymous page to login user.

if (req.http.Authorization || req.http.Cookie ~ "session" || req.http.Cookie ~ "Token") { return (pass); } #(varnish sitting cite from Manual:Varnish_caching)

How should I do to achive this goal?

Thank you!

Caching Special:Random
On two wikis I've configured to use Varnish 6 with the instructions on this page, I discovered that Special:Random always pointed to one page for logged-out users because Varnish was caching it. I was not able to find any information about this situation. After searching for how to exclude a particular URL from Varnish, I managed to solve the problem by inserting this piece of code into default.vcl (in the  block, above the   line): if (req.url ~ "^/wiki/Special:Random") { return (pass); } I hope this helps someone else. I don't know what the accepted solution is; this is quite likely not it, but it gets the job done. 9cfilorux (talk) 23:00, 11 October 2019 (UTC)

Varnish not starting (default.vcl' Line 76 Pos 21)
The backend server is ubuntu 20.04 LTS with varnish 4 installed.

Using the suggested configuration caused this error:


 * Feb 18 15:45:34 mainhost varnishd[1750650]: Error:
 * Feb 18 15:45:34 mainhost varnishd[1750650]: Message from VCC-compiler:
 * Feb 18 15:45:34 mainhost varnishd[1750650]: Expected return action name.
 * Feb 18 15:45:34 mainhost varnishd[1750650]: ('/etc/varnish/default.vcl' Line 76 Pos 21)
 * Feb 18 15:45:34 mainhost varnishd[1750650]:            return (miss);
 * Feb 18 15:45:34 mainhost varnishd[1750650]: ####--
 * Feb 18 15:45:34 mainhost varnishd[1750650]: Running VCC-compiler failed, exited with 2
 * Feb 18 15:45:34 mainhost varnishd[1750650]: VCL compilation failed
 * Feb 18 15:45:34 mainhost systemd[1]: varnish.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
 * Feb 18 15:45:34 mainhost systemd[1]: varnish.service: Failed with result 'exit-code'.

Nginx Cache
On my shared hosting, there is a website accelerator with Nginx. Is it possible to add in the localsettings.php for a better service Gribouillot (talk) 07:33, 13 April 2021 (UTC)


 * No, this won't work. I tried it years ago, to use the proxy response caching of nginx, but it only supports static files. It doesn't support HTTP purges. I originally wrote T178629 about that but it wasn't accepted. nginx is not a valid cache proxy for dynamic content. Use varnish for that. --Ciencia Al Poder (talk) 09:13, 13 April 2021 (UTC)

Visual Editor
To solve Visual Editor error 405, just configure Varnish to pass rest.php and api.php requests directly:

Automatic purge after page update
Varnish 7 and mediawiki (1.37, 1.38) work fine except automatic purge after page update. The setting $wgUseCdn = true; $wgCdnServers = [ '127.0.0.1']; or any permutation of that does not invoke anything in varnish, varnishstat does not indicate any purge/ban request. There is workaround like Manual:Job queue reading recent changes regularly and sending purge requests to varnish but it would be nice to achieve that natively. Pspviwki (talk) 17:45, 25 August 2022 (UTC)


 * If you set a debug log, you should see the PURGE URLs being sent to varnish. Try to request them with curl and see if that works. Ciencia Al Poder (talk) 17:36, 9 September 2022 (UTC)
 * Nothing in there. It logs other actions such as search or page access, but nothing for purge. I check the purge (success) in access_log, error_log, varnishstat, varnishncsa but not in debug log. Pspviwki (talk) 21:08, 17 September 2022 (UTC)