从Varnish重新验证缓存替换

时间:2016-10-19 09:49:15

标签: nginx varnish plesk http-caching

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

我们使用Varnish,主要用于' stale-while-revalidate'功能,以便我们可以发送整个页面或部分(使用ESI),而无需任何客户等待时间,同时缓存更新。

对于类似的缓存,Varnish有什么替代品吗?另一个"程序"可以在PLESK或任何PHP /服务器缓存上运行吗?

PLESK附带NGINX,但它似乎没有提供过时的重新验证'能力;我也知道鱿鱼在PLESK上不受支持。

2 个答案:

答案 0 :(得分:3)

实际上,nginx通过proxy_cache_use_staleNginx supports Cache-Control extensions since 1.11.10提供了重新验证的陈旧性:

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

是的,它不支持Cache-Control扩展,所以如果你的应用程序没有在Cache-Control中使用stale-while-revalidate,那么nginx就足够了。

答案 1 :(得分:1)

您可以尝试在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。

相关问题