Categories

XenForo 2.x + Nginx fastcgi_cache full page guest caching

You are here:
< All Topics

Nginx includes a FastCGI module which has directives for caching dynamic content that are served from the PHP backend. Setting this up removes the need for additional page caching solutions like reverse proxies (think Varnish) or application specific plugins. Content can also be excluded from caching based on the request method, URL, cookies, or any other server variable.

  • 1st: Install required Addon, to have persistent cookie for Login Users.
  • 2nd: Add this code into your Nginx config / nginx.conf, below http { block

For centminmod based server, above this line: https://github.com/centminmod/centminmod/blob/123.09beta01/config/nginx/nginx.conf#L33‚Äč
Assuming you didn’t modify the default xenforo cookie prefix which is xf_.NGINX:

### Start FastCGI Cache
map $http_cookie $nocachecookie {
    default                    0;
    ~xf_user                   1;
    ~xf_style_id               1;
    ~xf_lscxf_logged_in        1;
}
map $request_uri $nocacheuri {
    default                 0;
    ~^/register             1;
    ~^/login                1;
    ~^/misc/style           1;
}
fastcgi_cache_path /var/run/nginx_fastcgi_cache levels=1:2 keys_zone=fastcgicache:512m inactive=30m;
### End FastCGI Cache

NGINX:

### fastcgi_cache start
fastcgi_cache_methods    GET;
fastcgi_cache_key        $host$request_method$request_uri;
fastcgi_cache_lock       on;
fastcgi_cache_use_stale  error timeout invalid_header updating http_500 http_503;
fastcgi_ignore_headers   Cache-Control Expires Set-Cookie;
fastcgi_cache            fastcgicache;
fastcgi_no_cache         $nocachecookie $nocacheuri;
fastcgi_cache_bypass     $nocachecookie $nocacheuri;
fastcgi_cache_valid      200 301 302 303 404 5m;
add_header X-Cache-Status $upstream_cache_status;
### fastcgi_cache end
  • 4th: Save and then restart Nginx and PHP-FPM.
    nprestart for centminmod.
Table of Contents