• Hi,

    When I curl my site (ex. $curl -I http://www.lifebit.me/the-rains-of-castamere-2162/)
    the result is like this:

    HTTP/1.1 200 OK
    Server: nginx
    Date: Thu, 16 Aug 2012 23:05:16 GMT
    Content-Type: text/html
    Content-Length: 38824
    Last-Modified: Thu, 16 Aug 2012 20:45:20 GMT
    Connection: keep-alive
    Vary: Accept-Encoding
    Expires: Thu, 16 Aug 2012 21:45:20 GMT
    Cache-Control: no-cache
    X-Powered-By: W3 Total Cache/0.9.2.4
    Vary: Accept-Encoding, Cookie
    Pragma: public
    Cache-Control: max-age=3600, public, must-revalidate, proxy-revalidate
    Accept-Ranges: bytes

    Why are there 2 Cache-Control header? One with “no-cache” while the other one with “max-age”. Is that normal & OK?
    Many thanks!

    Regards,
    Andi A.

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter NanoG5

    (@nanog5)

    Now I uncheck “Set W3 Total Cache header” & “Enable HTTP (gzip) compression” in Browser Cache tab, “Cache SSL (https) requests” in Page Cache tab (yes, seems irrelevant), and then restart NGINX.
    Curl result:

    HTTP/1.1 200 OK
    Server: nginx
    Date: Fri, 17 Aug 2012 00:03:11 GMT
    Content-Type: text/html
    Content-Length: 72853
    Last-Modified: Fri, 17 Aug 2012 00:03:08 GMT
    Connection: keep-alive
    Vary: Accept-Encoding
    Expires: Fri, 17 Aug 2012 01:03:08 GMT
    Cache-Control: max-age=3597
    Vary: Cookie
    Pragma: public
    Cache-Control: max-age=3600, public, must-revalidate, proxy-revalidate
    Accept-Ranges: bytes

    At least now the first Cache-Control header is max-age, not no-cache. But is it normal & OK having two Cache-Control header? I believe the first Cache-Control header is from Page Cache.

    Plugin Contributor Frederick Townes

    (@fredericktownes)

    I can’t reproduce it. There should just be one Cache-control header. If you disable Set Cache Control header does it still return Cache Control headers?

    It should not set any Cache control headers then. There is no code that sets just single cache-control: no-cache or max-age so could be some conflict with other nginx conf higher up.

    Thread Starter NanoG5

    (@nanog5)

    Hi Frederick,

    I believe the first Cache-Control is from the Page Cache (Cache home page, Cache requests only.., Don’t cache page.. , are checked).

    If page cache expired (older than 3600 secs) then the header would be like this:

    curl -I www.lifebit.me
    HTTP/1.1 200 OK
    Server: nginx
    Date: Mon, 27 Aug 2012 15:18:25 GMT
    Content-Type: text/html
    Content-Length: 71674
    Last-Modified: Mon, 27 Aug 2012 13:31:34 GMT
    Connection: keep-alive
    Vary: Accept-Encoding
    Expires: Mon, 27 Aug 2012 14:31:34 GMT
    Cache-Control: no-cache
    Vary: Accept-Encoding, Cookie
    Pragma: public
    Cache-Control: public, must-revalidate, proxy-revalidate
    Accept-Ranges: bytes

    If page cache is not expired yet, the http header would be like this:

    curl -I www.lifebit.me
    HTTP/1.1 200 OK
    Server: nginx
    Date: Mon, 27 Aug 2012 15:22:37 GMT
    Content-Type: text/html
    Content-Length: 71762
    Last-Modified: Mon, 27 Aug 2012 15:22:31 GMT
    Connection: keep-alive
    Vary: Accept-Encoding
    Expires: Mon, 27 Aug 2012 16:22:31 GMT
    Cache-Control: max-age=3594
    Vary: Accept-Encoding, Cookie
    Pragma: public
    Cache-Control: public, must-revalidate, proxy-revalidate
    Accept-Ranges: bytes

    If there is no page cache:

    curl -I www.lifebit.me
    HTTP/1.1 200 OK
    Server: nginx
    Date: Mon, 27 Aug 2012 15:29:43 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    Vary: Accept-Encoding
    X-Pingback: http://www.lifebit.me/xmlrpc.php
    Last-Modified: Mon, 27 Aug 2012 15:29:43 GMT
    Vary: Cookie
    Expires: Mon, 27 Aug 2012 16:29:43 GMT
    Pragma: public
    Cache-Control: public, must-revalidate, proxy-revalidate

    If I disable Set cache control header:

    curl -I www.lifebit.me
    HTTP/1.1 200 OK
    Server: nginx
    Date: Mon, 27 Aug 2012 15:25:53 GMT
    Content-Type: text/html; charset=UTF-8
    Connection: keep-alive
    Vary: Accept-Encoding
    X-Pingback: http://www.lifebit.me/xmlrpc.php
    Last-Modified: Mon, 27 Aug 2012 15:25:53 GMT
    Vary: Cookie
    Expires: Mon, 27 Aug 2012 16:25:53 GMT

    I’m using W3TC generated nginx.conf in my web root, and I don’t have any specific nginx conf to handle static files or html.

    # BEGIN W3TC Page Cache cache
    location ~ /wp-content/w3tc/pgcache.*html$ {
        expires modified 3600s;
        add_header Vary "Accept-Encoding, Cookie";
        add_header Pragma "public";
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }
    location ~ /wp-content/w3tc/pgcache.*gzip$ {
        gzip off;
        types {}
        default_type text/html;
        expires modified 3600s;
        add_header Vary "Accept-Encoding, Cookie";
        add_header Pragma "public";
        add_header Cache-Control "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 application/x-javascript text/x-component text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
    location ~ \.(css|js|htc)$ {
        expires 31536000s;
        add_header Pragma "public";
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }
    location ~ \.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ {
        expires 3600s;
        add_header Pragma "public";
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }
    location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|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 "public, must-revalidate, proxy-revalidate";
    }
    # END W3TC Browser Cache
    # BEGIN W3TC Page Cache core
    rewrite ^(.*\/)?w3tc_rewrite_test$ $1?w3tc_rewrite_test=1 last;
    set $w3tc_rewrite 1;
    if ($request_method = POST) {
        set $w3tc_rewrite 0;
    }
    if ($query_string != "") {
        set $w3tc_rewrite 0;
    }
    if ($http_host != "www.lifebit.me") {
        set $w3tc_rewrite 0;
    }
    set $w3tc_rewrite2 1;
    if ($request_uri !~ \/$) {
        set $w3tc_rewrite2 0;
    }
    if ($request_uri ~* "(sitemap(_index)?\.xml(\.gz)?|[a-z0-9_\-]+-sitemap([0-9]+)?\.xml(\.gz)?)") {
        set $w3tc_rewrite2 1;
    }
    if ($w3tc_rewrite2 != 1) {
        set $w3tc_rewrite 0;
    }
    set $w3tc_rewrite3 1;
    if ($request_uri ~* "(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register|mail)\.php|\/feed\/|wp-.*\.php|index\.php)") {
        set $w3tc_rewrite3 0;
    }
    if ($request_uri ~* "(wp\-comments\-popup\.php|wp\-links\-opml\.php|wp\-locations\.php)") {
        set $w3tc_rewrite3 1;
    }
    if ($w3tc_rewrite3 != 1) {
        set $w3tc_rewrite 0;
    }
    if ($http_cookie ~* "(comment_author|wp\-postpass|wordpress_\[a\-f0\-9\]\+|wordpress_logged_in)") {
        set $w3tc_rewrite 0;
    }
    if ($http_user_agent ~* "(W3\ Total\ Cache/0\.9\.2\.4)") {
        set $w3tc_rewrite 0;
    }
    set $w3tc_ua "";
    set $w3tc_ref "";
    set $w3tc_ssl "";
    set $w3tc_enc "";
    if ($http_accept_encoding ~ gzip) {
        set $w3tc_enc _gzip;
    }
    set $w3tc_ext "";
    if (-f "$document_root/wp-content/w3tc/pgcache/$request_uri/_index$w3tc_ua$w3tc_ref$w3tc_ssl.html$w3tc_enc") {
        set $w3tc_ext .html;
    }
    if ($w3tc_ext = "") {
      set $w3tc_rewrite 0;
    }
    if ($w3tc_rewrite = 1) {
        rewrite .* "/wp-content/w3tc/pgcache/$request_uri/_index$w3tc_ua$w3tc_ref$w3tc_ssl$w3tc_ext$w3tc_enc" last;
    }
    # END W3TC Page Cache core

    The nginx.conf above is my current active configuration, Page Cache (cache home page, cache request only.., don’t cache pages..), Browser Cache (set expires header, set cache control header, enable http gzip, cache control policy: cache with validation public, must-revalidate, proxy-revalidate).

    Thanks for your reply Frederick, please let me know if you need any info from me.

    Hi,

    I’m having the same issue here; W3TC is the latest (stable)…

    Did you resolve this, NanoG5?

    Sincerely,

    Iiro

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: W3 Total Cache] Double "Cache-Control"’ is closed to new replies.