关于使用amazone的cloudfront
【IT168 资讯】cloudfront类似于CDN,文件存储在S3上,cloudfront的各个edge从S3上抓取文件,最终客户端按照地理位置的最近原则访问cloudfront的某个edge,cloudfront每24小时从S3上抓取一次文件,这个时间不能减小,如果你修改了S3上的文件,那么,你需要等24小时,cloudfront才会更新该文件,amazon推荐使用object version命名方法来为文件命名:
We recommend that you use the common technique of versioning to give yourself better control of your content. Versioning means that you assign each object in the origin server a version number. For example, instead of calling the file image.jpg, you call it image_1.jpg. Then when you want to start serving a new version of the file, you name that new file image_2.jpg, and you update your links to point to image_2.jpg. With versioning, you do not have to wait for an object to expire before you can serve a new version of it.
你可以为上传到S3上的文件设置http的header,如Cache-Control,等。
如果网站的国外访问量不是很大,完全可以将文件放到S3上,然后在国内建立squid来缓存S3上的文件。
在使用squid来缓存s3上的文件时,需要添加下面的配置,因为s3和cloudfront是使用类似apache的虚拟主机的,所以如果不使用域名去抓取文件时会出现403或404错误。
cache_peer test.s3.amazonaws.com parent 80 0 no-query originserver forceddomain=test.s3.amazonaws.com
# use 'forceddomain=name' to forcibly set the Host header
# of requests forwarded to this peer. Useful in accelerator
# setups where the server (peer) expects a certain domain
# name and using redirectors to feed this domain name
# is not feasible.
如何为s3上的文件修改header:
查看Amazon Simple Storage Service:
Getting Started Guide:
http://docs.amazonwebservices.com/AmazonS3/latest/gsg/
Developer Guide:
http://docs.amazonwebservices.com/AmazonS3/latest/
方法:使用amazon提供的几种语言中的一种,来上传文件,这样,就可以在上传时设置文件的http header了。
另外,s3上的文件的访问路径是:
bucket_name.s3.amazonaws.com
更加详细的资料,查看amazon的官方文档。