Stale-while-revalidate cache replacement from Varnish

走远了吗. 提交于 2019-12-08 02:16:34

问题


We are currently moving our servers to a new one, with PLESK 12.5 which doesn't support Varnish cache for our PHP applications.

We use Varnish, mostly for the 'stale-while-revalidate' capability, so that we can send whole pages or parts (using ESI) without any waiting time for any customer while cache is refreshing.

Is there any alternative to Varnish for a similar kind of cache ? Either another "program" that could run on PLESK, or any PHP/server cache ?

PLESK comes with NGINX, but it does not seem to provide 'stale-while-revalidate' capabilities ; I also know Squid isn't supported on PLESK.


回答1:


Actually nginx provides stale-while-revalidate by proxy_cache_use_stale and Nginx 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;
}

Yes, it does not support Cache-Control extension, with so if your application does not use stale-while-revalidate in Cache-Control header nginx will be enough.




回答2:


You may try to setup Varnish port in Plesk nginx config template:

# 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;

So for domains in proxy mode requests will be proxied to Varnish and than to Apache on port 7080.



来源:https://stackoverflow.com/questions/40127837/stale-while-revalidate-cache-replacement-from-varnish

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!