Page 1 of 1

Varnish on PHPbb 3.1.x board running into cookie problems

Posted: Mon Mar 21, 2016 4:54 pm
by Erpenator
Dear all,

I am trying to setup Varnish for my website + phpbb 3.1.6 board on a self hosted server. The board is highly customized with our own developed plugins and integrated into the website. This is one of the reasons we need Varnish to speed up the site for guests. Without Varnish the site is working perfectly, but we just want to make it faster.

In our Varnish configuration we we stripped the following cookies:
* PHPSESSID
* phpbb3_f338x_u
* phpbb3_f338x_k
* phpbb3_f338x_sid
This to be able to create a caching object and to strip all cookies when people visit the website as a guest. With this config the Varnish setup works okay for guests and is very fast!

We do not cache posts ($_POSTS) or any request to ucp.php. For posts and for ucp.php all request cookies may exists. Everything seems to work correctly and when we fill out our username and password we can see we are logged in correctly. The next request or click to a other page will log us out again because the cookies above are being stripped (just as the session id). This is why we created the cacheable object and we want to use it again after people login. This also works but only for one cookie.
This is by design by Varnish as you can read here: https://www.varnish-cache.org/trac/ticket/1058

We also added an extra cookie phpbb3_f338x_caching to let Varnish now that if that cookie exists it should not cache the results anymore. But because we can only set one set-cookie-header it means we can not restore all cookies. When we allow all cookies (set-cookies) to be set we hardly see any speed improvements and Varnish becomes useless.

I found a few topics where Varnish is being used with PHP BB and I can see in the headers phpbb.com is also still using Varnish. So to me it should be possible to use.

The question we have right now is what would be the "right" or normal Varnish setup for PHPBB 3.1.x?

Re: Varnish on PHPbb 3.1.x board running into cookie problems

Posted: Tue Mar 22, 2016 4:06 pm
by Mick
Why do you think you need varnish and why are you messing with phpBB cookie settings? Please fill out the Support Request Template and post it back here to enable us to assist you better. Please note server set up is beyond the scope of support on this site.

Re: Varnish on PHPbb 3.1.x board running into cookie problems

Posted: Tue Mar 22, 2016 4:15 pm
by Erpenator
Mick wrote:Why do you think you need varnish and why are you messing with phpBB cookie settings?
As you might know the purpose of Varnish is to speed the site up, the faster the website, the quicker a page is served and the faster pages are crawled by search engines. Which might result in more traffic. Currently the forum is slowing down the crawling of bots and serving the pages to visitors (in terms of miliseconds). This is due to some of the very dynamic plugins (which already use some form of caching).
Mick wrote:Please fill out the Support Request Template and post it back here to enable us to assist you better.
I had a look at the support template and I tried to include all the items that where needed. But here it is. Hope you can help.

Support Request Template
What version of phpBB are you using? phpBB 3.1.6
What is your board's URL? No answer given
Who do you host your board with? Self hosting
How did you install your board? I used the download package from phpBB.com
What is the most recent action performed on your board? Fresh Install
Is registration required to reproduce this issue? No
Do you have any MODs installed? No
Do you have any extensions installed? Yes
What extensions do you have installed? Self build extensions
What styles do you currently have installed? prosilver
What language(s) is your board currently using? NL
Which database type/version are you using? MySQL 5
What is your level of experience? Experienced with PHP and phpBB
What actions did you take (updating your board; installing a MOD, style or extension; etc.) prior to this problem becoming noticeable? No answer given
Please describe your problem. No answer given
Generated by SRT Generator

Re: Varnish on PHPbb 3.1.x board running into cookie problems

Posted: Mon Nov 28, 2016 11:12 am
by Ramon Fincken
any luck on this one ?

Re: Varnish on PHPbb 3.1.x board running into cookie problems

Posted: Mon Nov 28, 2016 11:18 am
by Erpenator
Unfortunately not. We had to give up because we couldn't get it fixed. I hope someone is still able to help us out.

Re: Varnish on PHPbb 3.1.x board running into cookie problems

Posted: Mon Nov 28, 2016 11:31 am
by Mick
Erpenator wrote:I had a look at the support template and I tried to include all the items that where needed.
What is your board's URL? No answer given
This is important so we can see the issue. Also, we wouldn't know how varnish works so you may be better off asking on a site that deals with that.

Re: Varnish on PHPbb 3.1.x board running into cookie problems

Posted: Mon Nov 28, 2016 11:40 am
by Erpenator
The test setup with Varnish is not accessible online without passwords and ip restrictions and we haven't implemented it on the live board so giving the url will not give you any extra information unfortunately.

phpbb.com is using Varnish for this board so someone who does the implantation for this site must know how to set it up or tell if it is impossible or not.

Re: Varnish on PHPbb 3.1.x board running into cookie problems

Posted: Mon Nov 28, 2016 11:48 am
by Mick
But the point is server setup is beyond the scope of this forum and you would be better off asking on a support site for the product you want to use.

Re: Varnish on PHPbb 3.1.x board running into cookie problems

Posted: Mon Nov 28, 2016 11:49 am
by Ramon Fincken
I am using varnish as well , but only enabled it for static files
/assets
/styles
/images
etc..
excluding any /adm paths

unfortunately whitelisting allow cookie set did not work here :(

Re: Varnish on PHPbb 3.1.x board running into cookie problems

Posted: Mon Nov 28, 2016 12:09 pm
by Erpenator
Server setup of Varnish is not the problem and I am not asking support for that, because there is only one way to set Varnish up server side (in regards to the cookie problem) and that is what we have done. So the other option left is that something must be different on phpbb.com in the software to make it work.

Therefore the question is what changes did phpbb.com made to make Varnish work with the forum software?

Re: Varnish on PHPbb 3.1.x board running into cookie problems

Posted: Mon Nov 28, 2016 3:04 pm
by Lumpy Burgertushie
a wild guess here. phpbb.com must not be using varnish to mess with the cookies at all. I find it hard to believe that all of the manipulations you describe above with the cookies could do anything but add time to the download of the pages.

phpbb depends on the cookies in order to work properly.

personally, I think that worrying about miliseconds of load time is a bit over the top.


good luck,
robert

Re: Varnish on PHPbb 3.1.x board running into cookie problems

Posted: Tue Nov 29, 2016 2:40 am
by Noxwizard
It's pretty much what's been speculated in this topic. We only process GET and HEAD requests with Varnish, we strip cookies from certain asset requests (images and the like), if the request isn't for an asset and it has cookies, we just return a pass. You can look at the response headers in your browser to see what's returning a hit or miss to see what we cache on.

Re: Varnish on PHPbb 3.1.x board running into cookie problems

Posted: Tue Nov 29, 2016 9:27 am
by Ramon Fincken
roger that, thats what I ended up with too.

Yet .. if we are able to cache HTML for guests too that would be great (and save a lot of webserver load)

Re: Varnish on PHPbb 3.1.x board running into cookie problems

Posted: Fri Mar 10, 2017 2:40 pm
by whocarez
Hi, for short time caching of guest requests, you can try the following in sub vcl_backend_response

Code: Select all

      if (beresp.http.Set-Cookie ~ "phpbb3_.+_u=1;")
    {
	set beresp.uncacheable = false;
	set beresp.ttl = 30s;
	unset beresp.http.Cache-Control;
        unset beresp.http.Set-Cookie;
	unset beresp.http.X-No-Cache;
	set beresp.http.Guest_Cache = {"Yes"};
    }
ttl would be for thirty seconds. With set beresp.http.Guest_Cache = {"Yes"}; you can check whether your condition works or not.
You only need to strip the cookies in sub vcl_recv for static files:

Code: Select all

  if (req.url ~ "^[^?]*\.(7z|avi|bmp|bz2|css|csv|doc|docx|eot|flac|flv|gif|gz|ico|jpeg|jpg|js|less|mka|mkv|mov|mp3|mp4|mpeg|mpg|odt|otf|ogg|ogm|opus|pdf|png|ppt|pptx|rar|rtf|svg|svgz|swf|tar|tbz|tgz|ttf|txt|txz|wav|webm|webp|woff|woff2|xls|xlsx|xml|xz|zip)(\?.*)?$") {
    unset req.http.Cookie;
    return (hash);
}