Stale-while-revalidate cache replacement from Varnish

梦想与她 提交于 2019-12-06 13:42:31

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.

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.

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