質問

現在、次のサイトを実行しています。
PressFlow 5.23.50
ワニス2.1.4

私が走っている問題のいくつかは、さまざまなドキュメントに基づいており、その一部は最新であり、その一部はそうではないと思います。

現在、これらの応答ヘッダーを取得します。

Server  Apache/2.2.3 (CentOS)
X-Powered-By    PHP/5.1.6
X-Drupal-Cache  HIT
Etag    "1294852404-1"
Cache-Control   public, max-age=0
Last-Modified   Wed, 12 Jan 2011 17:13:24 GMT
Expires Sun, 19 Nov 1978 05:00:00 GMT
Vary    Cookie,Accept-Encoding
Content-Encoding    gzip
Content-Type    text/html; charset=utf-8
X-Cacheable YES
Content-Length  7621
Date    Wed, 12 Jan 2011 17:59:49 GMT
X-Varnish   1305826372
Age 0
Via 1.1 varnish
Connection  keep-alive
X-Cache MISS

ワニス構成:
グローバルリダイレクトモジュールを使用しており、オンラインで見つけた適切なチェックを含めました。

backend default {
    .host = "127.0.0.1";
    .port = "7900";
#     .connect_timeout = 600s;
#     .first_byte_timeout = 600s;
#     .between_bytes_timeout = 600s;
#     .max_connections = 25000;
}


sub vcl_recv {
    set req.backend = default;



  set req.grace = 5m;

    remove req.http.X-Forwarded-For;
    set req.http.X-Forwarded-For = client.ip;

    # Properly handle different encoding types
    if (req.http.Accept-Encoding) {
        if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
            # No point in compressing these
            remove req.http.Accept-Encoding;
        } elsif (req.http.Accept-Encoding ~ "gzip") {
            set req.http.Accept-Encoding = "gzip";
        } elsif (req.http.Accept-Encoding ~ "deflate") {
            set req.http.Accept-Encoding = "deflate";
        } else {
            # unkown algorithm
            remove req.http.Accept-Encoding;
        }
    }

# Force lookup if the request is a no-cache request from the client
    if (req.http.Cache-Control ~ "no-cache") {
        return (pass);
    }

    ## Default request checks
    if (req.request != "GET" &&
        req.request != "HEAD" &&
        req.request != "PUT" &&
        req.request != "POST" &&
        req.request != "TRACE" &&
        req.request != "OPTIONS" &&
        req.request != "DELETE") {
            # Non-RFC2616 or CONNECT which is weird.
            return (pipe);
    }
    if (req.request != "GET" && req.request != "HEAD") {
        # We only deal with GET and HEAD by default
        return (pass);
    }
    if (req.request != "GET" && req.request != "HEAD") {
        # We only deal with GET and HEAD by default
        return (pass);
    }

    ## Modified from default to allow caching if cookies are set, but not http auth
    if (req.http.Authorization) {
        /* Not cacheable by default */
        return (pass);
    }

    ## Remove has_js and Google Analytics cookies.
    set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(__[a-z]+|has_js)=[^;]*", "");
    ## Remove a ";" prefix, if present.
    set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");
    ## Remove empty cookies.
    if (req.http.Cookie ~ "^\s*$") {
        unset req.http.Cookie;
    }
    ## Catch Drupal theme files  - THIS BREAKS UPDATE.PHP DO NOT USE
    #if (req.url ~ "^/sites/") {
    #    unset req.http.Cookie;
    #}
    # Catch Drupal misc files (like drupal.js and jquery.js)
    #if (req.url ~ "^/misc/") {
    #    unset req.http.Cookie;
    #}
    # Drupal js/css doesn't need cookies, cache them
    if (req.url ~ "^/modules/.*\.(js|css)\?") {
        unset req.http.Cookie;
    }

    ## Pass cron jobs and server-status
    if (req.url ~ "cron.php") {
       return (pass);
    }
    ## Don't cache install
    if (req.url ~ "install.php") {
        return (pass);
    }

    # if (req.url ~ "index.php") {
#   unset req.http.Cookie;
#     }

    # This is for Global Redirect.
    if (req.url ~ "node\?page=[0-9]+$") {
             set req.url = regsub(req.url, "node(\?page=[0-9]+$)", "\1");
             return (lookup);
    }

    ## Don't cache Drupal logged-in user sessions
    if (req.http.Cookie ~ "(VARNISH|DRUPAL_UID)") {
        return (pass);
    }

    return (lookup);
}

# Per-session cache
sub vcl_hash { if (req.http.Cookie) { set req.hash += req.http.Cookie; } }

sub vcl_fetch {
    # These status codes should always pass through and never cache.
    if (beresp.status == 404 || beresp.status == 503 || beresp.status == 500) {
        set beresp.http.X-Cacheable = "NO: beresp.status";
        set beresp.http.X-Cacheable-status = beresp.status;
        return (pass);
    }

    # Grace to allow varnish to serve content if backend is lagged
    set beresp.grace = 5m;


    if (!beresp.cacheable) {
        set beresp.http.X-Cacheable = "NO: !beresp.cacheable";
        return (pass);
    }

    # All tests passed, therefore item is cacheable
    set beresp.http.X-Cacheable = "YES";
    return (deliver);
}
#
sub vcl_deliver {
#    return (deliver);
   #add cache hit data
   if (obj.hits > 0) {
     #if hit add hit count
     set resp.http.X-Cache = "HIT";
     set resp.http.X-Cache-Hits = obj.hits;
   } else {
     set resp.http.X-Cache = "MISS";
   }
}

sub vcl_error {
    if (obj.status == 503 && req.restarts < 5) {
        set obj.http.X-Restarts = req.restarts;
        restart;
    }
}

また、これをsettings.phpの下部に追加しました:

$conf['reverse_proxy'] = TRUE;
$conf['reverse_proxy_addresses'] = array('127.0.0.1');

また、Drupalはパフォーマンスページで「積極的なキャッシュ」に設定されています。

私が見逃している小さなことはありますか、それとも誰かが私に向かって私を指さすことができる方向がありますか?

役に立ちましたか?

解決

多くのモジュールは、セッションを開始するか、ページをキャッシュできないようにするCookieを追加します。ここにある多くの可能性と解決策があります:

https://wiki.fourkitchens.com/display/pf/modules+ that+break+caching,++how+ to+fix+them

どのモジュールがセッションを開始しているかをデバッグするいくつかのヒント。

http://groups.drupal.org/node/66888

他のヒント

Lullabotの記事も見ていきます。

複数のWebサーバーを使用して、高可用性のためにワニスを構成します

http://www.lullabot.com/articles/varnish-multiple-web-servers-drupal

彼らは、Drupalが開始するための完全なワニス構成と、適切なワニスステータスチェックPHPスクリプトを持っています。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top