WordPress.org

Support

Support » Plugins and Hacks » Nginx: disk enhanced page cache breaks

Nginx: disk enhanced page cache breaks

Viewing 4 replies - 1 through 4 (of 4 total)
  • I think I was able to correct the nginx configuration.

    The default is:

    # BEGIN W3TC Page Cache core
    set $w3tc_rewrite 1;
    if ($request_method = POST) {
        set $w3tc_rewrite 0;
    }
    if ($query_string != "") {
        set $w3tc_rewrite 0;
    }
    if ($request_uri !~ \/$) {
        set $w3tc_rewrite 0;
    }
    if ($http_cookie ~* "(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle)") {
        set $w3tc_rewrite 0;
    }
    if ($http_user_agent ~* "(W3\ Total\ Cache/0\.9\.2\.7)") {
        set $w3tc_rewrite 0;
    }
    set $w3tc_enc "";
    if ($http_accept_encoding ~ gzip) {
        set $w3tc_enc _gzip;
    }
    if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.html$w3tc_enc") {
      set $w3tc_rewrite 0;
    }
    if ($w3tc_rewrite = 1) {
        rewrite .* "/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.html$w3tc_enc" last;
    }
    # END W3TC Page Cache core

    My edits are below. I changed the default rewrite variable to 0 and, added quotes around the “_gzip” variable, and got rid of the document_root variable and changed the variable to 1 if the cached file exists:

    # BEGIN W3TC Page Cache core
    set $w3tc_rewrite 0;
    if ($request_method = POST) {
        set $w3tc_rewrite 0;
    }
    if ($query_string != "") {
        set $w3tc_rewrite 0;
    }
    if ($request_uri !~ \/$) {
        set $w3tc_rewrite 0;
    }
    if ($http_cookie ~* "(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle)") {
        set $w3tc_rewrite 0;
    }
    if ($http_user_agent ~* "(W3\ Total\ Cache/0\.9\.2\.7)") {
        set $w3tc_rewrite 0;
    }
    set $w3tc_enc "";
    if ($http_accept_encoding ~ gzip) {
        set $w3tc_enc "_gzip";
    }
    if (-f "/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.html$w3tc_enc") {
      set $w3tc_rewrite 1;
    }
    if ($w3tc_rewrite = 1) {
        rewrite .* "/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.html$w3tc_enc" last;
    }
    # END W3TC Page Cache core

    oh, and I also changed the nginx.conf file’s ownership to root so that w3tc wouldn’t overwrite the changes.

    Thanks for sharing the solution. I posted an alternative solution for version 0.9.2.8 at http://wordpress.org/support/topic/bug-disk-enhanced-caching-on-nginx-fails-due-to-a-typo-in-the-nginxconf-file?replies=4#post-3837623 . Hope that helps.

    Jesper, I want to thank you… I’ve been banging my head for hours because of page cache rewrite rules… You saved me.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Nginx: disk enhanced page cache breaks’ is closed to new replies.