WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
SOLUTION: Nginx Conf for last W3TC update (7 posts)

  1. ramirojoaquin
    Member
    Posted 11 months ago #

    Hi, a few days ago, when update the plugin to the last version (0.9.2.10) the minify feature was totally broken. I discovered that the problem was caused by the nginx config.
    I only change the order off the blocks and now its working fine.
    I want to share this with you:

    # BEGIN W3TC Minify cache
    location ~ /wp-content/cache/minify.*\.js$ {
        types {}
        default_type application/x-javascript;
        expires modified 31536000s;
        add_header X-Powered-By "W3 Total Cache/0.9.2.10";
        add_header Vary "Accept-Encoding";
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
    }
    location ~ /wp-content/cache/minify.*\.css$ {
        types {}
        default_type text/css;
        expires modified 31536000s;
        add_header X-Powered-By "W3 Total Cache/0.9.2.10";
        add_header Vary "Accept-Encoding";
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
    }
    location ~ /wp-content/cache/minify.*js\.gzip$ {
        gzip off;
        types {}
        default_type application/x-javascript;
        expires modified 31536000s;
        add_header X-Powered-By "W3 Total Cache/0.9.2.10";
        add_header Vary "Accept-Encoding";
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
        add_header Content-Encoding gzip;
    }
    location ~ /wp-content/cache/minify.*css\.gzip$ {
        gzip off;
        types {}
        default_type text/css;
        expires modified 31536000s;
        add_header X-Powered-By "W3 Total Cache/0.9.2.10";
        add_header Vary "Accept-Encoding";
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
        add_header Content-Encoding gzip;
    }
    # END W3TC Minify cache
    # BEGIN W3TC Page Cache cache
    location ~ /wp-content/cache/page_enhanced.*html$ {
        expires modified 3600s;
        add_header X-Powered-By "W3 Total Cache/0.9.2.10";
        add_header Vary "Accept-Encoding, Cookie";
        add_header Pragma "public";
        add_header Cache-Control "max-age=3600, public, must-revalidate, proxy-revalidate";
    }
    location ~ /wp-content/cache/page_enhanced.*gzip$ {
        gzip off;
        types {}
        default_type text/html;
        expires modified 3600s;
        add_header X-Powered-By "W3 Total Cache/0.9.2.10";
        add_header Vary "Accept-Encoding, Cookie";
        add_header Pragma "public";
        add_header Cache-Control "max-age=3600, public, must-revalidate, proxy-revalidate";
        add_header Content-Encoding gzip;
    }
    # END W3TC Page Cache cache
    # BEGIN W3TC Browser Cache
    gzip on;
    gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
    location ~ \.(css|htc|js|js2|js3|js4)$ {
        expires 31536000s;
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
        add_header X-Powered-By "W3 Total Cache/0.9.2.10";
    }
    location ~ \.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ {
        expires 3600s;
        add_header Pragma "public";
        add_header Cache-Control "max-age=3600, public, must-revalidate, proxy-revalidate";
        add_header X-Powered-By "W3 Total Cache/0.9.2.10";
    }
    location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ {
        expires 31536000s;
        add_header Pragma "public";
        add_header Cache-Control "max-age=31536000, public, must-revalidate, proxy-revalidate";
        add_header X-Powered-By "W3 Total Cache/0.9.2.10";
    }
    # END W3TC Browser Cache
    # BEGIN W3TC Minify core
    rewrite ^/wp-content/cache/minify.*/w3tc_rewrite_test$ /wp-content/plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 last;
    set $w3tc_enc "";
    if ($http_accept_encoding ~ gzip) {
        set $w3tc_enc .gzip;
    }
    if (-f $request_filename$w3tc_enc) {
        rewrite (.*) $1$w3tc_enc break;
    }
    rewrite ^/wp-content/cache/minify/(.+/[X]+\.css)$ /wp-content/plugins/w3-total-cache/pub/minify.php?test_file=$1 last;
    rewrite ^/wp-content/cache/minify/(.+\.(css|js))$ /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1 last;
    # END W3TC Minify core
    # 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)") {
        set $w3tc_rewrite 0;
    }
    set $w3tc_ssl "";
    if ($scheme = https) {
        set $w3tc_ssl _ssl;
    }
    set $w3tc_enc "";
    if ($http_accept_encoding ~ gzip) {
        set $w3tc_enc _gzip;
    }
    set $w3tc_ext "";
    if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_ssl.html$w3tc_enc") {
        set $w3tc_ext .html;
    }
    if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_ssl.xml$w3tc_enc") {
        set $w3tc_ext .xml;
    }
    if ($w3tc_ext = "") {
      set $w3tc_rewrite 0;
    }
    if ($w3tc_rewrite = 1) {
        rewrite .* "/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_ssl$w3tc_ext$w3tc_enc" last;
    }
    # END W3TC Page Cache core
    # BEGIN W3TC Skip 404 error handling by WordPress for static files
    if (-f $request_filename) {
        break;
    }
    if (-d $request_filename) {
        break;
    }
    if ($request_uri ~ "(robots\.txt|sitemap(_index)?\.xml(\.gz)?|[a-z0-9_\-]+-sitemap([0-9]+)?\.xml(\.gz)?)") {
        break;
    }
    if ($request_uri ~* \.(css|htc|js|js2|js3|js4|html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$) {
        return 404;
    }
    # END W3TC Skip 404 error handling by WordPress for static files

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

  2. Nic Windley
    Member
    Posted 10 months ago #

    Excellent, well spotted ramirojoaquin.

    Actually I'm struggling to get nginx to set headers and expires correctly.

    I've got nginx installed (as a proxy only) and created a separate wordpress.conf file (using your code above) which I've included into my [vhostname].conf file.

    No matter what I do headers and expires remain the same.

    Any suggestions how to resolve this would be appreciated.

    Thanks,

    Nic

    p.s. I could not find a tab inside w3 total cache with any nginx rules - do you know if these were removed in the latest upgrade ?

  3. ramirojoaquin
    Member
    Posted 10 months ago #

    Hi Nic,
    I have the nginx conf outside my root dir. I modify the header directly from my .conf file, not from w3.
    My config is Debian 6 + PHP 5.4 FPM + Nginx. And to see the auto-generated rules from W3 i go to the "Install" tab. The only problem is that code has to be modify like i post to work propertly.

  4. Nic Windley
    Member
    Posted 10 months ago #

    Thanks ramirojoaquin.

    I got it working in the end. All nginx mods / rules added to core are done using include files (so I don't lose them) and as I had not included the files in the correct place for each vhost it was actualy ignoring them.

    As soon as I included them inside the location / { } block it worked.

    Strange, I don't see any any rules for nginx in the W3TC "Install" tab ?

  5. tarrioin
    Member
    Posted 8 months ago #

    Hi, thanks for sharing your config file.
    You mind posting your file:
    / etc / nginx / nginx.conf (is where you configure nginx)
    / etc / nginx / sites-enabled / (In posting one of these to use wordpress to compare would help me a lot. both to me and to others)

    Also posting here my working configuration with speed I get 25ms in wordpress websites.

    [Moderator note - Please see the forum guidelines re: posting code - and use a pastebin for lengthy code like that - http://codex.wordpress.org/Forum_Welcome#Posting_Code

  6. Nic Windley
    Member
    Posted 7 months ago #

    Did you find what you needed tarrioin ?

  7. Kurt Flint
    Member
    Posted 7 months ago #

    Hey there @tarrion: Did you transfer your config to pastebin, or did the moderator just delete your code and leave the thread crippled? May as well delete the whole thread if so.

    I'll post any significant differences if I find them between what I have and what you have. The mods from W3TC seem pretty good though. And to get the code in your install page Nic you check a box at the bottom of the General page. At least that is what works for me, though I have never UN checked it now that I think about it!

    Kurt

Reply

You must log in to post.

About this Plugin

About this Topic