[英]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.