我们目前正在将我们的服务器迁移到一个新的服务器,PLESK 12.5不支持我们的PHP应用程序的Varnish缓存。
我们使用Varnish,主要是为了"在重新验证时过期"的功能,这样我们就可以发送整个页面或部分(使用ESI),而不会在缓存刷新时等待任何客户。
对于类似类型的缓存,是否有任何替代Varnish的方法?或者另一个可以在PLESK上运行的"程序",或者任何PHP/服务器缓存?
PLESK是NGINX自带的,但它似乎不提供"在重新验证时失效"的功能;我也知道Squid不支持PLESK。
实际上nginx通过proxy_cache_use_stale提供了stale-while-revalidate,并且nginx从1.11.10开始支持Cache-Control扩展:
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就足够了
你可以尝试在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。