• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Nginx Fastcgi_cache configuration for Xenforo Board

RoldanLT

Well-known member
#1
I got it working 99% as far as I tested :D
Big credits to @hungphutho and @eva2000 of centminmod community :)

My config:
nginx.conf
For others, should be above server{ block.
For centminmod users: above include /usr/local/nginx/conf/conf.d/*.conf;
Code:
### fastcgi_cache
###
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=phcornercache:500m inactive=1d max_size=2g;
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 end

php.conf above }
Code:
### fastcgi_cache
###              
fastcgi_cache phcornercache;
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
fastcgi_cache_valid  200 302 15m;
fastcgi_cache_valid  301 1d;
fastcgi_cache_valid  404 5m;
fastcgi_cache_valid  any 15m;
add_header X-Cached $upstream_cache_status;
###
### fastcgi_cache end

Domain.conf above location / {
Code:
### fastCgi cache
    set $no_cache 0;

    # POST requests should always go to PHP
    if ($request_method = POST) {
        set $no_cache 1;
    }  

    # Don't use the cache for logged in users
    if ($http_cookie ~* "xf_session_admin|xf_user|xf_user_admin") {
        set $no_cache 1;
    }

    # Don't cache uris containing the following segments
    if ($request_uri ~* "(admin.php|/account/|/conversations/|/misc/|/online/|/login/|/register/|/login|/register|/library/|/internal_data/)") {
        set $no_cache 1;
    }   
    ### fastCgi end
 
Last edited:

RoldanLT

Well-known member
#5
@eva2000 explain it here: https://theadminzone.com/threads/ng...htspeed-what-are-you-using.88599/#post-607153
eva2000 said:
varnish cache and xcache do different things, proper comparison would be

in terms of php opcode caching

apache* + xcache (php opcode cache)
vs
apache* + apc (php opcode cache)
vs
apache* + eaccelerator (php opcode cache)

* switch out apache for nginx or litespeed web server


in terms of web acceleration

apache + varnish
vs
nginx + varnish
vs
litespeed web server + varnish
vs
nginx + nginx fastcgi_cache
vs
litespeed web server + litespeed cache

But no i haven't tried nginx + varnish cache - would be the most time consuming combination of them all as it's quite alot of admin work to do with nginx configuration/htaccess/rewrite customisation + varnish vcl rule sets each script you load on your server.
 

Floren

Well-known member
#7
@RoldanLT, you just made it possible to display a bunch of user conversations and other private info to everyone, in your forums. :D
I already told you what to do on AXIVO forums. Please make sure you don't spread this information without proper testing. I logged out of Centminmod forums, just to be safe.
 
Last edited:

RoldanLT

Well-known member
#8
you just made it possible to display a bunch of user conversations and other private info to everyone, in your forums. :D
What makes you say that?
Conversations page are already Bypass with this:
Code:
 # Don't use the cache for logged in users
    if ($http_cookie ~* "xf_session_admin|xf_user|xf_user_admin") {
        set $no_cache 1;
    }
 

RoldanLT

Well-known member
#10
Ok, Just changed this.
Code:
 # Don't cache uris containing the following segments
    if ($request_uri ~* "(/admin.php|/account/|/conversations/|/misc/|/online/|/login/|/register/|/login|/register|/library/|/internal_data/)") {
        set $no_cache 1;
    }
 

Floren

Well-known member
#11
You're adding things blindly, without trying to understand where the actual problem is. Have a look at XenForo login to understand where is your problem.
 

RoldanLT

Well-known member
#12
Can't edit 1st post (n)

Now change to:
Code:
### fastCgi cache
    set $no_cache 0;

    # Filter out POST and HEAD requests for caching!
    if ($request_method ~ ^(HEAD|POST)$) {
    set $noCache 1;
    }

    # Don't use the cache for logged in users
    if ($http_cookie ~* "xf_session_admin|xf_user|xf_user_admin|xf_style_id=69|xf_style_id=70|xf_style_id=71") {
        set $no_cache 1;
    }

    # Don't cache uris containing the following segments
    if ($request_uri ~* "(admin.php|/account/|/conversations/|/misc/|/online/|/login/|/register/|/login|/register|/library/|/internal_data/)") {
        set $no_cache 1;
    }  
    ### fastCgi end
 

MattW

Well-known member
#13
I've been testing this on my debian server. Setting the values that @RoldanLT has set above when logged in doesn't send anything to the nginx cache, and setting the extra header shows BYPASS on the cache

upload_2014-9-15_18-37-47.png

You might also want to add /logout/ to the $request_uri
 

RoldanLT

Well-known member
#16
It was triggering errors then displaying 403 access denied on my test site when I logged out until I added it to the uri
Aw :D
Thanks, didn't tried to logout so I didn't encounter that issue.

Now my problem is, a user can't login unless "Stay logged in" is check :eek:
 
Last edited:

RoldanLT

Well-known member
#20
For now, I modified 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>
With this:
Code:
<input type="hidden" name="remember" checked="checked" value="1" />
Solved :)