WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
Nginx: disk enhanced page cache breaks (5 posts)

  1. tarkin79
    Member
    Posted 1 year ago #

    On nginx - disk enhanced caching breaks, I get 404 errors. I think it has to do with the nginx.conf rules that it creates, but I'm not sure where. Using disk standard caching seems to work fine.

    Version 0.9.2.7.

    http://wordpress.org/extend/plugins/w3-total-cache/

  2. tarkin79
    Member
    Posted 1 year ago #

    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
  3. tarkin79
    Member
    Posted 1 year ago #

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

  4. Pothi
    Member
    Posted 1 year ago #

    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.

  5. ETFovac
    Member
    Posted 1 year ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.