【问题标题】:Set content-encoding to specific files via aws command通过 aws 命令将内容编码设置为特定文件
【发布时间】:2017-06-02 18:41:58
【问题描述】:

我通过 aws 命令部署静态应用程序。 我通过此命令将所有文件从我的文件夹复制到 s3 存储桶:

aws s3 sync C:\app s3://myBucket

我想将内容编码设置为 gzip,仅用于 js、jpg 和 html 文件。 我通过此命令成功为所有文件夹执行此操作:--content-encoding gzip 我怎样才能只为特定的文件类型做到这一点?

【问题讨论】:

    标签: amazon-s3 aws-cli


    【解决方案1】:

    这是旧的,但我需要找到一种方法来做到这一点:我没有使用 Cloudfront,而且我们使用的代理不能处理 gzip...所以:

    1. 排除所有文件
    2. 根据需要包括单个文件类型
    3. 设置适当的编码/选项

    下面我还要添加访问控制和缓存控制,并删除本地目录中不存在的 s3 中的所有文件

    我已将 JS/CSS 与所有图像、html 分开,但这可能不是必需的。

    然而,我确实没有为每个人明确设置内容编码/缓存--include,因此遇到了很多麻烦,因此我将其设置如下以使其更清晰。

    我能找到的 AWS 文档没有提到这些东西

    aws s3 sync ./dist/ s3://{bucket} \
    --exclude "*" \
    --include "static/*.ico" --acl "public-read" --cache-control no-cache \
    --include "static/*.png" --acl "public-read" --cache-control no-cache \
    --include "*.html" --acl "public-read" --cache-control no-cache \
    --include "static/img/*.svg" --acl "public-read" --cache-control no-cache \
    --delete \
    
    aws s3 sync ./dist/ s3://{bucket} \
    --exclude "*" \
    --include "static/js/*.js" --acl "public-read" --cache-control  no-cache --content-encoding gzip \
    --include "static/css/*.css" --acl "public-read" --cache-control no-cache --content-encoding gzip \
    --delete \ 
    

    仅从 s3 提供服务的速度提升非常小。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-16
      • 2013-11-23
      • 2014-11-09
      • 2021-02-10
      • 2020-06-17
      • 2021-05-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多