【问题标题】:Laravel Forge (Nginx) Gzip and browser caching + SSLLaravel Forge (Nginx) Gzip 和浏览器缓存 + SSL
【发布时间】:2017-05-14 05:50:04
【问题描述】:

我正在尝试改进浏览器缓存以及使用 gzip 压缩。 在我的调查中,我发现消息来源说在启用 SSL 时不应启用压缩。

我在设置时遇到了这个 nginx 设置。 https://gist.github.com/reedmaniac/adfa2740323d08de25bd

谁能建议我是否可以盲目地遵循上述设置,或者我需要保留默认的 Forge 设置?

这是我网站上的谷歌开发者页面速度结果,表明我需要利用浏览器缓存和压缩: https://developers.google.com/speed/pagespeed/insights/?url=https%3A%2F%2Fwww.itutorialist.com

【问题讨论】:

  • 在我的调查中,我发现消息来源说在启用 SSL 时不应启用压缩。 - 这并非完全错误,但远非正确。您不应该为可能包含机密的内容(如 CSRF 令牌)启用压缩,但可以为非敏感内容启用压缩。详情请参阅security.stackexchange.com/questions/20406/…。这也意味着启用 gzip 的配置可能有问题,也可能没有问题,具体取决于您的内容。除此之外,这与缓存无关。
  • 感谢您的解释。鉴于我在我的网站上设置了 SSL,是否有任何简单/标准的 Nginx 设置方法来改进压缩和缓存,这样我就不会成为 BREACH/CRIME 攻击的受害者?抱歉,我在这方面没有足够的知识,仍在挖掘以了解更多信息。
  • 这不是 nginx 特有的。这取决于您的应用程序,即哪些部分包含敏感数据,哪些部分不包含。如果您的应用程序中没有任何内容包含敏感数据,那么您可以压缩所有内容。

标签: php laravel nginx laravel-forge


【解决方案1】:

这是我在 nginx.conf forge inside serve 中的设置

# browser caching of static assets
    location ~*  \.(jpg|jpeg|png|gif|ico|css|js|pdf)$ {
        expires 7d;
    }

    server_tokens off;

    #GZIP
    # Enable gzip compression.
    gzip on;

    # Compression level (1-9).
    # 5 is a perfect compromise between size and CPU usage, offering about
    # 75% reduction for most ASCII files (almost identical to level 9).
    gzip_comp_level    5;

    # Don't compress anything that's already small and unlikely to shrink much
    # if at all (the default is 20 bytes, which is bad as that usually leads to
    # larger files after gzipping).
    gzip_min_length    256;

    # Compress data even for clients that are connecting to us via proxies,
    # identified by the "Via" header (required for CloudFront).
    gzip_proxied       any;

    # Tell proxies to cache both the gzipped and regular version of a resource
    # whenever the client's Accept-Encoding capabilities header varies;
    # Avoids the issue where a non-gzip capable client (which is extremely rare
    # today) would display gibberish if their proxy gave them the gzipped version.
    gzip_vary          on;

    # Compress all output labeled with one of the following MIME-types.
    gzip_types
      application/atom+xml
      application/javascript
      application/json
      application/ld+json
      application/manifest+json
      application/rss+xml
      application/vnd.geo+json
      application/vnd.ms-fontobject
      application/x-font-ttf
      application/x-web-app-manifest+json
      application/xhtml+xml
      application/xml
      font/opentype
      image/bmp
      image/svg+xml
      image/x-icon
      text/cache-manifest
      text/css
      text/plain
      text/vcard
      text/vnd.rim.location.xloc
      text/vtt
      text/x-component
      text/x-cross-domain-policy;

希望对大家有帮助

【讨论】:

    【解决方案2】:

    您似乎正确配置了 GZIP。您当前的问题是您不是setting an appropriate Cache-Control header,并且您的图像很差optimised

    【讨论】:

    • 感谢您的指导,我将通过您共享的链接来设置适当的缓存控制标头。我对 Nginx 配置没有很好的了解。这是我需要为 Nginx 配置中的缓存控制标头遵循的一般设置,还是因情况而异?据我了解,并非所有内容都应该被盲目缓存,这可能会导致一些漏洞
    猜你喜欢
    • 1970-01-01
    • 2016-09-16
    • 2014-11-29
    • 2015-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-18
    • 2015-07-13
    相关资源
    最近更新 更多