@VladKursitis

Почему Varnish не обновляет страницу для пользователей?

Здравствуйте,

Я использую связку из NGINX + PHP5 + VARNISH + Wordpresss , но видимо Varnish не настроен до конца. Проблема заключается в том что сайт обновляеться для простых пользователей от 30 минут до часа. В то время если сидеть на сайте как администратор обновления сайта вступают в силу сразу.
Вот настройки Varnisha - default.vcl:

backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

# Drop any cookies sent to WordPress.
sub vcl_recv {

    if (req.http.Accept-Encoding) {
        if (req.http.Accept-Encoding ~ "gzip") {
            # If the browser supports it, we'll use gzip.
            set req.http.Accept-Encoding = "gzip";
        }
        else if (req.http.Accept-Encoding ~ "deflate") {
            # Next, try deflate if it is supported.
            set req.http.Accept-Encoding = "deflate";
        }
        else {
            # Unknown algorithm. Remove it and send unencoded.
            unset req.http.Accept-Encoding;
        }
    }


    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);
    }

    # Remove cookies set by Google Analytics (pattern: '__utmABC')
    if (req.http.Cookie) {
        set req.http.Cookie = regsuball(req.http.Cookie,
            "(^|; ) *__utm.=[^;]+;? *", "\1");
        if (req.http.Cookie == "") {
            remove req.http.Cookie;
        }
    }

      # always pass through POST requests and those with basic auth

 if (req.http.Authorization || req.request == "POST") {
        return (pass);
    }

    # Do not cache these paths
    if (req.url ~ "^/wp-cron\.php$" ||
        req.url ~ "^/xmlrpc\.php$" ||
        req.url ~ "^/wp-admin/.*$" ||
        req.url ~ "^/wp-includes/.*$" ||
        req.url ~ "\?s=") {
            return (pass);
    }

    if (req.url ~ "preview=true") {
        return(pass);
    }

    # logged in users must always pass
    if( req.url ~ "^/wp-(login|admin)|sa28nvxkuf5d" || req.http.Cookie ~ "wordpress_logged_in_" ){
        return (pass);
    }

    # Define the default grace period to serve cached content
    set req.grace = 30s;

    # accept purges from w2tc and varnish http purge
    if (req.request == "PURGE") {
        return (lookup);
    }

    # don't cache search results
    if( req.url ~ "\?s=" ){
        return (pass);
    }

    # bypass export CSV , you can replace your url pattern with /exportlimit/all/
    if ( req.url ~ ".*/exportlimit/all/.*" ) {
        set req.http.connection = "close";
        return(pipe);
    }


    if (!(req.url ~ "wp-(login|admin)|sa28nvxkuf5d")) {
        unset req.http.cookie;
    }

    # By ignoring any other cookies, it is now ok to get a page
    unset req.http.Cookie;
    return (lookup);
}

# Drop any cookies WordPress tries to send back to the client.
sub vcl_fetch {
 # remove some headers we never want to see
    unset beresp.http.Server;
    unset beresp.http.X-Powered-By;

    # don't cache search results
    if( req.url ~ "\?s=" ){
        return (hit_for_pass);
    }

    if (!(req.url ~ "wp-(login|admin)|sa28nvxkuf5d")) {
        unset beresp.http.set-cookie;
    }

    # don't cache response to posted requests or those with basic auth
    if ( req.request == "POST" || req.http.Authorization ) {
        return (hit_for_pass);
    }

    # only cache status ok
    if ( beresp.status != 200 ) {
        return (hit_for_pass);
    }

     # If our backend returns 5xx status this will reset the grace time
    # set in vcl_recv so that cached content will be served and
    # the unhealthy backend will not be hammered by requests
    if (beresp.status == 500) {
        set beresp.grace = 60s;
        return (restart);
    }

    # GZip the cached content if possible
    if (beresp.http.content-type ~ "text") {
        set beresp.do_gzip = true;
    }

    # if nothing abovce matched it is now ok to cache the response
    set beresp.ttl = 24h;
    return (deliver);
}


sub vcl_miss {
    # Set up invalidation of the cache so purging gets done properly
    if (req.request == "PURGE") {
        purge;
        error 200 "Purged.";
    }
    return (fetch);
}


Есть идеи как можно исправить данный баг? Проблема исправляется если перезагрузить Varnish, но если снова что нибудь изменить на сайте, новость или картинку, апдейты не вступают в силу и приходится снова перезагружать Varnish. Уже устали искать проблему... Буду ждать ваших идей и советов, спасибо за внимание.
  • Вопрос задан
  • 2796 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
29 мар. 2024, в 17:04
5000 руб./за проект
29 мар. 2024, в 17:03
3000 руб./за проект
29 мар. 2024, в 16:58
3000 руб./за проект