Manual talk:Varnish caching

From MediaWiki.org
Jump to navigation Jump to search

if-none-match support added?[edit]

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[edit]

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?[edit]

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[edit]

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:

--- a/includes/SquidPurgeClient.php
+++ b/includes/SquidPurgeClient.php
@@ -148,7 +148,21 @@
         */
        public function queuePurge( $url ) {
                $url = SquidUpdate::expand( str_replace( "\n", '', $url ) );
-               $this->requests[] = "PURGE $url HTTP/1.0\r\n" .
+               # Modify PURGE request for Varnish 2.x and up
+               # See http://www.mediawiki.org/wiki/Thread:Project:Support_desk/Varnish_purging_not_working_since_Varnish_2.x
+               # Basically, we need to convert 
+               #    PURGE http://wiki.example.com/mediawiki/index.php?title=Sandbox&action=history HTTP/1.0
+               # to
+               #    PURGE /mediawiki/index.php?title=Sandbox&action=history HTTP/1.0
+               #    Host: wiki.example.com
+               # in the purge request header.
+               $urlArr = parse_url( $url );
+               if( $urlArr['query'] != "" )
+                       $urlQuery = "?" . $urlArr['query'];
+               else
+                       $urlQuery = "";
+               $this->requests[] = "PURGE " . $urlArr['path'] . $urlQuery . " HTTP/1.0\r\n" .
+                       "Host: " . $urlArr['host'] . "\r\n" .
                        "Connection: Keep-Alive\r\n" .
                        "Proxy-Connection: Keep-Alive\r\n" .
                        "User-Agent: " . Http::userAgent() . ' ' . __CLASS__ . "\r\n\r\n";

Varnish 4 purging[edit]

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

Varnish 4.x not working & mobile example?[edit]

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:

if (beresp.ttl < 48h) {
   set beresp.uncacheable = true;
   return (deliver);
}

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[edit]

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?[edit]

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[edit]

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 sub vcl_recv block, above the return (hash); 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)