Credits to @eva2000 @hungphutho @MattW and @Floren for their guidance with I started digging it .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, required addon: https://xenforo.com/community/resources/logged-in-cookie.4961/
To have persistent cookie for Login Members.
Then add this code into your Nginx Config.
nginx.conf
below http { block
or just selected domain config you may have above server{ block.
Code:
### FastCGI Cache ################
map $http_cookie $nocachecookie {
default 0;
~xf_fbUid 1;
~xf_user 1;
~xf_logged_in 1;
}
map $request_uri $nocacheuri {
default 0;
~^/register 1;
~^/login 1;
~^/validate-field 1;
~^/captcha 1;
~^/lost-password 1;
~^/two-step 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 ################
php.conf
above the last line }.
or at the very bottom of this block
location ~ \.php$ {
Code:
### fastcgi_cache ###
fastcgi_cache fastcgicache;
fastcgi_cache_bypass $nocachecookie $nocacheuri;
fastcgi_no_cache $nocachecookie $nocacheuri;
fastcgi_cache_valid 200 202 302 404 403 5m;
fastcgi_cache_valid 301 1h;
fastcgi_cache_valid any 1m;
add_header X-Cache $upstream_cache_status;
### fastcgi_cache end ###
Save and then restart Nginx and PHP-FPM.
Optional, to have xf_user cookie on every Login Members.
Modify template helper_login_form and login_bar_form.
Replace:
Code:
<label class="rememberPassword"><input type="checkbox" name="remember" value="1" id="ctrl_pageLogin_remember" tabindex="3" /> {xen:phrase stay_logged_in}</label>
Code:
<input type="hidden" name="remember" checked="checked" value="1" />
Benefits?
Same as Varnish and LiteSpeed Full Page Cache .
More Info:
http://nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_cache
https://www.digitalocean.com/community/tutorials/how-to-setup-fastcgi-caching-with-nginx-on-your-vps
https://www.scalescale.com/tips/nginx/configure-nginx-fastcgi-cache/
Last edited: