amazon-s3 - 使用 ansibles s3_sync 或相关模块设置 s3 对象的 Content-Type 和 Content-Encoding 标头
问题描述
使用 ansible 的s3_sync
模块(下面的任务)没有指定 Content-Type 标头,因此浏览器无法解读。我想知道如何使用mime_type
选项或其他 ansible 模块设置 Content-Type 标头。
- name: S3 | sync gzip assets in build directory
s3_sync:
aws_access_key: "{{ lookup('env', 'AWS_ACCESS_KEY_ID') }}"
aws_secret_key: "{{ lookup('env', 'AWS_SECRET_ACCESS_KEY') }}"
bucket: "{{ s3_bucket }}"
file_root: "{{ s3_sync_dir }}"
mime_map:
.gz: application/gzip
.json: application/text
.png: image/png
.ico: image/vnd.microsoft.icon
.svg: image/svg+xml
file_change_strategy: force
permission: public-read
cache_control: "public, max-age=31536000"
include: "*"
region: us-east-1
我想做类似的事情:
mime_map:
.js.gz:
headers: "Content-Encoding=application/gzip, Content-Type=application/js"
.css.gz:
headers: "Content-Encoding=application/gzip, Content-Type=text/css"
.json: application/text
.png: image/png
.ico: image/vnd.microsoft.icon
.svg: image/svg+xml
请注意:文件被散列到浏览器缓存中,因此任何解决方案都需要模式匹配,例如:files: **/*.js.gz, headers: "Content-Type=application/javascript"
解决方案
推荐阅读
- c# - 根据输入数字查找十进制值
- windows - 如何仅使用脚本获取最后 5 个字符的 Office 许可证密钥
- c# - 统一坠落精灵
- javascript - 计算年龄并检查值是否正常
- python-3.x - 谷歌云功能:达到 --max-instances 时的行为
- google-cloud-platform - gsutil 和 gcloud 有什么区别?
- php - 如何在 TWIG 中获取 Cookie 值?
- elasticsearch - ElasticsearchException:运行机器学习本机代码失败
- user-interface - 统一以不同纵横比为 UI 设置动画的问题
- javascript - 使用 rss-feed 逐项自动滚动网页