来自 Varnish 的 Stale-while-revalidate 缓存替换

Stale-while-revalidate cache replacement from Varnish

我们目前正在将我们的服务器转移到一个新的服务器上,PLESK 12.5 不支持我们的 PHP 应用程序的 Varnish 缓存。

我们使用 Varnish,主要是为了 'stale-while-revalidate' 功能,这样我们就可以发送整个页面或部分内容(使用 ESI),而无需在缓存刷新时等待任何客户。

是否有类似缓存的 Varnish 替代品?可以在 PLESK 上 运行 的另一个 "program",或任何 PHP/server 缓存?

PLESK 附带 NGINX,但它似乎不提供 'stale-while-revalidate' 功能;我也知道 PLESK 不支持 Squid。

实际上nginx通过proxy_cache_use_stale and Nginx supports Cache-Control extensions since 1.11.10提供stale-while-revalidate:

location / {
    ...
    proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504;
    proxy_cache_background_update on;
}

是的,它不支持Cache-Control扩展,所以如果你的应用程序不使用stale-while-revalidate在Cache-Control header nginx将够了。

您可以尝试在 Plesk nginx 配置模板中设置 Varnish 端口:

# it's for Plesk 17
cat /usr/local/psa/admin/conf/templates/custom/domain/service/proxy.php
<?php
/**
 * @var Template_VariableAccessor $VAR
 * @var array $OPT
 */
?>
<?php if ($OPT['ssl']): ?>
        proxy_pass https://<?php echo $OPT['ipAddress']->proxyEscapedAddress . ':' . '6081' ?>;
<?php else: ?>
        proxy_pass http://<?php echo $OPT['ipAddress']->proxyEscapedAddress . ':' . '6081' ?>;
<?php endif ?>
        proxy_set_header Host             $host;
        proxy_set_header X-Real-IP        $remote_addr;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
<?php if (!$VAR->domain->physicalHosting->proxySettings['nginxTransparentMode'] && !$VAR->domain->physicalHosting->proxySettings['nginxServeStatic']): ?>
        proxy_set_header X-Accel-Internal /internal-nginx-static-location;
<?php endif ?>
        access_log off;

因此对于处于代理模式的域,请求将被代理到 Varnish,而不是端口 7080 上的 Apache。