W3 Total Cache – Converting Apache rewrites to Nginx [closed]

Based on your comment, here’s the solution for an Nginx-Apache stack with “disk: enhanced” page cache method in W3 Total Cache plugin…

location / {
    error_page 418 = @cachemiss;
    recursive_error_pages on;

    if ($request_method = POST) { return  418; }

    if ($query_string != "") { return 418; }

    if ($request_uri ~* "(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register|mail)\.php|wp-.*\.php|index\.php|wp\-comments\-popup\.php|wp\-links\-opml\.php|wp\-locations\.php)") { return 418; }

    if ($http_cookie ~* "comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle") { return 418; }

    try_files "/wp-content/cache/page_enhanced/$host/$uri/_index.html" =418;

    # optional code
    # expires 30m;
    # add_header "X-W3TC-Cache" "HIT :)";
}

location @cachemiss {
    # pass the requests to backend (Apache)

    # optional header
    # add_header "X-W3TC-Cache" "Miss :(";
}

# other directives
# for example
location ~* \.php$ {
    # pass PHP requests to Apache
}

# another example
location /wp-admin {
    # pass requests to Apache
}

The above solution follows the best practices of using an if statement in Nginx and works correctly, when modified, for WPSC. I hope that helps.