php - Laravel Forge (Nginx) Gzip 和浏览器缓存 + SSL

标签 php laravel nginx laravel-forge

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

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

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

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

最佳答案

这是我在服务内的 nginx.conf forge 中的设置

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

希望对大家有帮助

关于php - Laravel Forge (Nginx) Gzip 和浏览器缓存 + SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43960784/

相关文章:

nginx - 同一主机内的docker容器可以有相同的端口吗

nginx - 为什么要在 Flask 应用程序中使用 uWSGI 和主管,而不仅仅是主管?

php - 将在 JavaScript 和 PHP 中产生相同结果的字符串哈希函数

javascript - JSON_ENCONDE -> getJSON 不起作用

php - 使用 PHP 和 JS 到服务器的系统时间

php - 模拟 Laravel 的 Request::segment 方法

laravel - Laravel 5 中的反向多态关系

php - 显示来自 WordPress 帖子的图像

javascript - Laravel 5.0 : Calculation using LaravelCollective and jQuery

nginx - 如何使用 ffmpeg 和 aparat.com 设置 rtmp?