角ssr清漆用法

问题描述 投票:0回答:1

它有效,但不影响性能。我可以正确使用吗?

/ etc / varnish / default.vcl

    backend default { 
    .host = "127.0.0.1"; 
    .port = "4000"; }

我在nginx配置中添加了消失端口而不是4000

 location / {
      proxy_pass          http://localhost:6081;
}

我的Angular应用(google pagespeed)桌面性能为99%,但移动性能为40-60%。

node.js angular performance nginx varnish
1个回答
0
投票

Varnish开箱即用的行为尊重HTTP缓存最佳实践。

这意味着:

  • 仅缓存HTTP GET和HTTP HEAD调用
  • 当请求包含cookie标头时,不提供来自缓存的响应
  • 当请求包含authorization标头时,不提供来自缓存的响应
  • [存在set-cookie标头时,不将响应存储在缓存中
  • cache-control标头为零TTL]或包含以下内容时,不要在缓存中存储响应:no-cacheno-storeprivate

在所有情况下,Varnish都将尝试从缓存提供服务或将其存储在缓存中。

这是用VCL编写的行为:https://github.com/varnishcache/varnish-cache/blob/6.0/bin/varnishd/builtin.vcl

适应现实世界

尽管这些缓存最佳做法很有意义,但是当您查看现实世界时,它们并不现实。在现实世界中,我们一直都在使用Cookie。

这就是为什么您可能必须编写一些VCL代码

才能更改缓存的行为。为此,您必须非常熟悉应用程序的HTTP终结点,以及使用cookie的部分。
  • 您的应用中在服务器端使用Cookie值的部分必须从缓存中排除
  • 未使用Cookie值的应用程序部分将存储在缓存中
  • 仅在客户端使用的跟踪cookie必须被剥夺
  • 如何检查正在发生的事情

varnishlog二进制文件将帮助您了解通过Varnish的流量类型以及Varnish如何处理该流量。

我已经写了一篇关于此的深入博客文章,请看一下:https://feryn.eu/blog/varnishlog-measure-varnish-cache-performance/

写VCL

一旦确定了导致性能下降的原因,就可以编写VCL来缓解。请访问docs网站以了解VCL:https://varnish-cache.org/docs/6.0/index.html

这里是参考资料,用户指南,甚至是教程。

祝你好运

© www.soinside.com 2019 - 2024. All rights reserved.