XenForo Forum with Nginx fastcgi_cache full page guest caching

XenForo Forum with Nginx fastcgi_cache full page guest caching

rdn

Well-known member
When using https://xenforo.com/community/resources/cta-featured-threads-portal.2599/ as your home page portal, logged-in visits to the home page are as though the user is logged-out.
What setting is required to correct this?
Any addon installed under XenForo should behave what cookie the XF will provide.
So this addon is already enough:
  • 1st: Install required Addon, to have persistent cookie for Login Users.

More cookie filter on step
  • 5th: To have xf_user cookie persist on every Login Users.
 

Mouth

Well-known member
Had to immediately disable this add-on functionality. Within a couple of hours of operation, had several users saying they were being shown as logged-in as someone else. Even experienced this myself.
Ouch :(
 

rdn

Well-known member
Had to immediately disable this add-on functionality. Within a couple of hours of operation, had several users saying they were being shown as logged-in as someone else. Even experienced this myself.
Ouch :(
That's because you use custom cookie name.
Code:
netrider_user=xxxxxxx;
netrider_logged_in=1;
netrider_session=xxxxxxx
 

rdn

Well-known member
From my guide,you need to change this steps also.
From:
Code:
map $http_cookie $nocachecookie {
     default                   0;
    ~xf_fbUid                  1;
    ~xf_user                   1;
    ~xf_logged_in              1;
}
to
Code:
map $http_cookie $nocachecookie {
     default                         0;
    ~netrider_fbUid                  1;
    ~netrider_user                   1;
    ~netrider_logged_in              1;
}
Or revert your custom cookie naming on config.php.
 
Last edited:

rdn

Well-known member

rdn

Well-known member
RoldanLT updated XenForo Forum with Nginx fastcgi_cache full page guest caching with a new update entry:

Add support for serving separate cache Mobile/Desktop visitors.

map $http_user_agent $mobile_request {
default 0;
~*android|ip(hone|od)|windows\s+(?:ce|phone) 1;
~*symbian|sonyericsson|samsung|lg|blackberry 1;
~*mobile 1;
}

fastcgi_cache_key $scheme$request_method$host$request_uri$mobile_request;
Read the rest of this update entry...
 

Amin Sabet

Well-known member
New post has HTTP/1.1 303, so 1 minute caching.
I meant that I don't need 1 minute updates for guests, so I can set that everything to 1h for extra caching, right?

From my guide,you need to change this steps also.
Would be good to add a warning to the resource about this issue to help prevent anyone else from getting that surprise that Mouth got. Can be a significant security issue when members end up logged in as one another, admins, etc.

Add support for serving separate cache Mobile/Desktop visitors.
Did you add this for PHCorner? Is it needed with usual responsive styles or only for dedicated mobile styles?
 
Last edited:

Solidus

Well-known member
I'll try this some day. Already getting 1.5/1.8 second load times without using centminmod or even nginx. Who knows what I could achieve.
 

rdn

Well-known member
I meant that I don't need 1 minute updates for guests, so I can set that everything to 1h for extra caching, right?
Yes you can change the cache expire time to whatever you want.
But 1 hour ( 1h or 60m) is too much I guess :).

Would be good to add a warning to the resource about this issue to help prevent anyone else from getting that surprise that Mouth got. Can be a significant security issue when members end up logged in as one another, admins, etc.
I already add note about that since Yesterday (y).

Did you add this for PHCorner? Is it needed with usual responsive styles or only for dedicated mobile styles?
Yes I'm using it on my Site.

That isn't needed for responsive Site, but I have custom widgets that differ on desktop and mobile view.
Different placement of ads also for desktop and mobile that's why I need it.

I'll try this some day. Already getting 1.5/1.8 second load times without using centminmod or even nginx. Who knows what I could achieve.
So still inlove with Apache? :).
Try and see the performance boost (y).
 

Amin Sabet

Well-known member
I have fastcgi_cache and ngx_pagespeed enabled together, and I'm not seeing a problem. Page headers say "X-Cache HIT" and images are being optimized by ngx_pagespeed as expected. Am I missing something?

Example: https://www.mu-43.com/
 

eva2000

Well-known member
I have fastcgi_cache and ngx_pagespeed enabled together, and I'm not seeing a problem. Page headers say "X-Cache HIT" and images are being optimized by ngx_pagespeed as expected. Am I missing something?

Example: https://www.mu-43.com/
i see that interesting but you should benchmark it (without cloudflare masking php-fpm performance) as cache-control: max-age=0, no-cache headers will prevent fastcgi_cache caching usually

i think it's because you have set to ignore cache control headers
Code:
fastcgi_ignore_headers          Cache-Control Expires Set-Cookie;
This may cause issues with pagespeed rewritten/optimised resources as they maybe cached before they're fully optimised due to pagespeed rewrite/optimisations may requiring several page reloads to fully optimise a resource

https://developers.google.com/speed/pagespeed/module/configuration

Preserving HTML caching headers
By default, PageSpeed serves all HTML with Cache-Control: no-cache, max-age=0 because the transformations made to the page may not be cacheable for extended periods of time.
If you want to force PageSpeed to leave the original HTML caching headers you can add:

Apache:

Code:
ModPagespeedModifyCachingHeaders off
Nginx:
Code:
pagespeed ModifyCachingHeaders off;
Note: We do not suggest you turn this option off. It breaks PageSpeed's caching assumptions and can lead to unoptimized HTML being served from a proxy caches set up in front of the server. If you do turn it off, we suggest that you do not set long caching headers to HTML or users may receive stale or unoptimized content.
@Amin Sabet FYI, your ngx_pagespeed version in Centmin Mod is outdated 1.12.34.2-beta is latest https://community.centminmod.com/threads/ngx_pagespeed-1-12-34-1-beta-released.9754/
 
Last edited:

Amin Sabet

Well-known member
i see that interesting but you should benchmark it
With Cloudflare paused, here are some data from my home page below. I did 27 runs (3x9) at each setting. I didn't disable ads because I wanted "real world" results.

ngx_pagespeed off, fastcgi_cache on:
https://www.webpagetest.org/result/161226_ED_TCH/
https://www.webpagetest.org/result/161226_8F_TBJ/
https://www.webpagetest.org/result/161226_HB_TBQ/

ngx_pagespeed off, no page cache for guests:
https://www.webpagetest.org/result/161226_V5_TFA/
https://www.webpagetest.org/result/161226_8X_TEW/
https://www.webpagetest.org/result/161226_C2_TEP/

ngx_pagespeed off, bd cache on:
https://www.webpagetest.org/result/161226_E0_TM9/
https://www.webpagetest.org/result/161226_2M_TKX/
https://www.webpagetest.org/result/161226_AD_TKT/

ngx_pagespeed on, fastcgi_cache on:
https://www.webpagetest.org/result/161226_J8_T6H/
https://www.webpagetest.org/result/161226_BR_T7R/
https://www.webpagetest.org/result/161226_3W_TB6/

ngx_pagespeed on, no page cache for guests:
https://www.webpagetest.org/result/161226_XX_TFD/
https://www.webpagetest.org/result/161226_3N_TEX/
https://www.webpagetest.org/result/161226_WN_TET/

ngx_pagespeed on, bd cache on:
https://www.webpagetest.org/result/161226_KD_TM6/
https://www.webpagetest.org/result/161226_JP_TM4/
https://www.webpagetest.org/result/161226_QA_TM3/

Seems that fastcgi_cache shortens what webpagetest calls "first byte", ngx_pagespeed lowers total page weight (due to compressing images), and those two benefits are preserved when using both together.
 
Last edited:

Amin Sabet

Well-known member
Comparing just ngx_pagespeed on state with fastcgi_cache either on or off and taking the median of 27 runs in each condition:

Time to First Byte* is shorter with fastcgi_cache on: 285ms vs 408ms

Time to Start Render* is shorter with fastcgi_cache on: 1599ms vs 1892ms

Speed Index* is lower (better) with fastcgi_cache enabled: 2011 vs 2250

*using webpagetest definitions of these terms
 

Amin Sabet

Well-known member
Comparing just ngx_pagespeed off state with fastcgi_cache either on or off and taking the median of 27 runs in each condition:

Time to First Byte* is shorter with fastcgi_cache on: 236ms vs 383ms

Time to Start Render* is shorter with fastcgi_cache on: 1590ms vs 1792ms

Speed Index* is lower (better) with fastcgi_cache enabled: 2159 vs 2227

*using webpagetest definitions of these terms
 

Amin Sabet

Well-known member
Comparing just ngx_pagespeed on state with fastcgi_cache vs bd cache pages for guest and taking the median of 27 runs in each condition:

Time to First Byte* is shorter with fastcgi_cache: 285ms vs 505ms

Time to Start Render* is shorter with fastcgi_cache: 1599ms vs 2083ms

Speed Index* is lower (better) with fastcgi_cache: 2011 vs 2518

None of my tests showed much of an advantage of bd cache pages for guests compared with fastcgi_cache or even no page cache for guests at all. It's possible I implemented bd cache pages for guests incorrectly.
 
Top