XenForo Forum with Nginx fastcgi_cache full page guest caching

Status
Not open for further replies.

rdn

Well-known member
Since we both use centminmod, I think you need to create another php.conf.
Like php_forum_index.conf:
Code:
location = /forum/index.php {
        include /usr/local/nginx/conf/php_forum_index.conf;
    }
With different cache valid value.
 

silence

Well-known member
Small issue though, doubt it can be fixed.

For guests they are unable to change styles. I know there's the 'xf_edit_style_id' cookie but whitelisting that would disable cache for all :(
 

Amin Sabet

Well-known member
Thanks for sharing this @RoldanLT

I got an error, Nginx failed to restart when adding code to nginx.conf

I was able to get it working for one site by adding the code outside of server block in domain.conf

However, when I tried to add the same code for other sites / domains, I got:

Code:
Starting nginx: nginx: [emerg] the same path name "/tmp/nginx_fastcgi_cache" used in /usr/local/nginx/conf/conf.d/audiogearclub.com.conf:21 and in /usr/local/nginx/conf/conf.d/foreverfilm.org.conf:22

Then I tried specifying /tmp/nginx_fastcgi_cache for one site, /tmp/nginx_fastcgi_cache2 for another site, etc, and got a different error:

Code:
Starting nginx: nginx: [emerg] duplicate zone "fastcgicache" in /usr/local/nginx/conf/conf.d/foreverfilm.org.conf:22

Before I go any further down this path, is fastcgi_cache better than using [bd] Cache to cache pages for Guests? It's a lot easier to do that one :).
 

eva2000

Well-known member
fyi fastcgi_cache won't work with ngx_pagespeed due to headers pagespeed uses, pagespeed optimized assets won't be cached at all
 

rdn

Well-known member
Thanks for sharing this @RoldanLT

I got an error, Nginx failed to restart when adding code to nginx.conf

I was able to get it working for one site by adding the code outside of server block in domain.conf

However, when I tried to add the same code for other sites / domains, I got:

Code:
Starting nginx: nginx: [emerg] the same path name "/tmp/nginx_fastcgi_cache" used in /usr/local/nginx/conf/conf.d/audiogearclub.com.conf:21 and in /usr/local/nginx/conf/conf.d/foreverfilm.org.conf:22

Then I tried specifying /tmp/nginx_fastcgi_cache for one site, /tmp/nginx_fastcgi_cache2 for another site, etc, and got a different error:

Code:
Starting nginx: nginx: [emerg] duplicate zone "fastcgicache" in /usr/local/nginx/conf/conf.d/foreverfilm.org.conf:22

Before I go any further down this path, is fastcgi_cache better than using [bd] Cache to cache pages for Guests? It's a lot easier to do that one :).
Instead of doing that, I recommend you follow the guide but use different php.conf file for every domain you have.
And specifically create new php.conf (like php_fastcgi_cache.conf) that has fastcgi_cache on it.
 

Amin Sabet

Well-known member
Instead of doing that, I recommend you follow the guide but use different php.conf file for every domain you have.
And specifically create new php.conf (like php_fastcgi_cache.conf) that has fastcgi_cache on it.

Okay, I am going to disable ngx_pagespeed and try the guide again. Do I need to use a different path and zone for each domain?
 
Last edited:

rdn

Well-known member
Can you explain in a little more detail the part about using different php.conf for every domain?
I'll use the minimal config guide here: https://xenforo.com/community/threa...-full-page-guest-caching.110806/#post-1025390

Minimal Config :).

nginx.conf
Add below http { block
For centminmod, above this code: https://github.com/centminmod/centminmod/blob/123.09beta01/config/nginx/nginx.conf#L33
Code:
### FastCGI Cache ################
map $http_cookie $nocachecookie {
     default                   0;
    ~xf_logged_in              1;
}

fastcgi_cache_path              /tmp/nginx_fastcgi_cache levels=1:2 keys_zone=fastcgicache:200m inactive=30m;
fastcgi_cache_key               $scheme$request_method$host$request_uri;
fastcgi_cache_lock              on;
fastcgi_cache_use_stale         error timeout invalid_header updating http_500;
fastcgi_ignore_headers          Cache-Control Expires Set-Cookie;
### FastCGI Cache ################

Create new file on /usr/local/nginx/conf/, lets name it php_fastcgi_cache.conf
Copy contents from /usr/local/nginx/conf/php.conf to the newly created conf file php_fastcgi_cache.conf.

On php_fastcgi_cache.conf ad above/before the last line }.
Code:
### fastcgi_cache ###
fastcgi_cache           fastcgicache;
fastcgi_cache_bypass    $nocachecookie;
fastcgi_no_cache        $nocachecookie;
fastcgi_cache_valid     5m;
add_header X-Cache      $upstream_cache_status;
### fastcgi_cache end ###

Edit your XenForo Domain Config at /usr/local/nginx/conf/conf.d/yourdomain.com.conf.
Replace every instance of php.conf with php_fastcgi_cache.conf.

Run nprestart.

Done :)
 
Last edited:

Amin Sabet

Well-known member
Thank you so much. I will try this now. Is there any advantage to setting fastcgi_cache_path to a RAM location with tmpfs?
 
Status
Not open for further replies.
Top