1. 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

Discussion in 'Server Configuration and Hosting' started by RoldanLT, Sep 13, 2014.

  1. RoldanLT

    RoldanLT Well-Known Member

    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: Sep 14, 2014
    vishall likes this.
  2. Sheratan

    Sheratan Well-Known Member

    What's the difference between this and opcache/xcache?
     
  3. RoldanLT

    RoldanLT Well-Known Member

    Zend opcache and Xcache is only for PHP Caching.
     
  4. Sheratan

    Sheratan Well-Known Member

    So this is for html and css?
     
  5. RoldanLT

    RoldanLT Well-Known Member

    @eva2000 explain it here: https://theadminzone.com/threads/ng...htspeed-what-are-you-using.88599/#post-607153
     
  6. RoldanLT

    RoldanLT Well-Known Member

  7. Floren

    Floren Well-Known Member

    @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: Sep 14, 2014
  8. RoldanLT

    RoldanLT Well-Known Member

    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;
        }
     
  9. Floren

    Floren Well-Known Member

    That's not true.
     
  10. RoldanLT

    RoldanLT Well-Known Member

    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;
        } 
     
  11. Floren

    Floren Well-Known Member

    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.
     
  12. RoldanLT

    RoldanLT Well-Known Member

    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
     
  13. MattW

    MattW Well-Known Member

    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 likes this.
  14. RoldanLT

    RoldanLT Well-Known Member

    Added /logout/ uri (But looks like already filtered by cookie, added just to be sure), Thanks @MattW
     
  15. MattW

    MattW Well-Known Member

    It was triggering errors then displaying 403 access denied on my test site when I logged out until I added it to the uri
     
    RoldanLT likes this.
  16. RoldanLT

    RoldanLT Well-Known Member

    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: Sep 15, 2014
  17. RoldanLT

    RoldanLT Well-Known Member

    Added "/lost-password/" filter uri.
     
  18. Floren

    Floren Well-Known Member

    Now you finally understand what I mean by checking the XenForo login. :)
    And adding those exclusions you are performing with crazy IF's are useless anyways.
     
    RoldanLT likes this.
  19. RoldanLT

    RoldanLT Well-Known Member

    Perhaps you can advice :unsure:
     
  20. RoldanLT

    RoldanLT Well-Known Member

    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 :)
     

Share This Page