简体   繁体   English

AWS Elastic Beanstalk / S3 / CloudFront缓存控制标头

[英]AWS Elastic Beanstalk / S3 / CloudFront Cache-Control Header

I have a Flask application deployed using AWS Elastic Beanstalk. 我有一个使用AWS Elastic Beanstalk部署的Flask应用程序。 I am using S3 for storage and CloudFront as a cdn. 我正在使用S3进行存储,并将CloudFront用作CDN。 How can I add the Cache-Control header to the static files served by Elastic Beanstalk application? 如何将Cache-Control标头添加到Elastic Beanstalk应用程序提供的静态文件中?

Elastic Beanstack assumes a very simplistic setup when it comes to static files. 对于静态文件,Elastic Beanstack假定设置非常简单。 Basically assumes that you will serve them from the server itself. 基本上假设您将从服务器本身为它们提供服务。

Most people, like you, use S3 and CloudFront instead, but unfortunately, this requires you to deploy these static files manually (ie without eb ). 像您一样,大多数人都改为使用S3和CloudFront,但是不幸的是,这需要您手动部署这些静态文件(即,不使用eb )。

If your static files don't change much, you could just upload them manually to your s3 origin. 如果您的静态文件变化不大,则可以将其手动上传到s3源。 But may be better to script this. 但是编写此脚本可能更好。

I personally use Gulp to manage all my static files. 我个人使用Gulp来管理我的所有静态文件。 Gulp has two handy packages to deploy to S3, and setup the Cache controls: Gulp有两个方便的软件包可部署到S3,并设置Cache控件:

It's not hard to do the same with Boto, but Gulp also processes my CSS/JS files, including creating a cache friendly deployment name (eg app-1234.css). 使用Boto进行同样的操作并不难,但是Gulp也会处理我的CSS / JS文件,包括创建一个缓存友好的部署名称(例如app-1234.css)。 My deployment to Elastic Beanstalk is then: 我到Elastic Beanstalk的部署是:

gulp deploy  # Where Gulp processes CSS/JS/Images and uploads to S3/CF
eb deploy    # To deploy my python code

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 S3 / CloudFront,提供标题为“Cache-Control:max-age = 365000000,immutable”的所有文件 - S3/CloudFront, serve all files with header “Cache-Control: max-age=365000000, immutable” 从PHP AWS SDK设置S3对象的缓存控制HTTP标头 - Set Cache-Control HTTP Header for S3 Objects from PHP AWS SDK Origin Cache-Control在AWS Cloudfront上不起作用 - Origin Cache-Control not working on AWS Cloudfront 在 AWS Cloudfront 中如何添加缓存控制? - In AWS Cloudfront how to add cache-control? 如何在亚马逊云端设置 Cache-Control Header? - How to set Cache-Control Header in amazon cloudfront? 要从AWS CloudFront删除缓存控制标头吗? - Remove Cache-Control headers from AWS CloudFront? 将缓存控制元数据添加到AWS Elastic Transcoder输出 - Add Cache-Control Metadata to AWS Elastic Transcoder Output 如何为相同内容类型的所有S3对象添加缓存控制标头? - How to add cache-control header for all S3 objects of a same content type? 适用于Elastic Beanstalk应用程序的AWS S3凭证 - AWS S3 Credentials for Elastic Beanstalk app 为要上传到AWS S3的图像设置Expires和Cache-Control标头 - Setting Expires and Cache-Control headers for images that are being uploaded to AWS S3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM