设置不带S3的Amazon Cloudfront

编程入门 行业动态 更新时间:2024-10-14 16:27:02
本文介绍了设置不带S3的Amazon Cloudfront的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用Cloudfront从我的静态网站提供图像和CSS。我已经阅读了无数文章,展示了如何使用Amazon S3进行设置,但是我只想将文件托管在主机上,并使用Cloud Front加快上述文件的交付速度,我不确定该如何处理。

I want to use Cloudfront to serve images and CSS from my static website. I have read countless articles showing how to set it up with Amazon S3 but I would like to just host the files on my host and use cloud front to speed up delivery of said files, I'm just unsure on how to go about it.

到目前为止,我已经使用自己的Origin Domain和CName在CloudFront上创建了一个发行版并进行了部署。

So far I have created a distribution on CloudFront with my Origin Domain and CName and deployed it.

来源域:example.me CName media.example.me

Origin Domain: example.me CName media.example.me

我为我的域添加了CNAME:

I added the CNAME for my domain:

media目的地为xxxxxx.cloudfront的.mydomain

media.mydomain with destination xxxxxx.cloudfront

现在这是我被卡住的地方吗?我是否需要将HTML中的链接更新为该cname,以便如果样式表为 example.me /stylesheets/screen.css 是否将其更改为 http://media.example。 me / stylesheets / screen.css

Now this is where I'm stuck? Do I need to update the links in my HTML to that cname so if the stylesheet was example.me/stylesheets/screen.css do I change that to media.example.me/stylesheets/screen.css

以及样式表中的图像../images/image1.jpg到 media.example.me/images/image1.jpg ?

and images within the stylesheet that were ../images/image1.jpg to media.example.me/images/image1.jpg?

刚发现它有点困惑如何链接所有内容,这是我第一次真正使用CDN时。

Just finding it a little confusing how to link everything it's the first time I have really dabbled in using a CDN.

谢谢

推荐答案

是的,您将必须更新HTML中的路径以指向CDN。通常,如果您具有部署/构建过程,则可以在那时进行链接更改(以便开发时可以使用本地文件)。

Yes, you will have to update the paths in your HTML to point to CDN. Typically if you have a deployment/build process this link changing can be done at that time (so that development time can use the local files).

这里处理的是CSS / JS等的版本控制。您可能会经常更改CSS / JS。进行任何更改时,CDN通常需要24小时才能反映出来。 (另一种选择是使CDN上的文件无效,但这是明确收费的,因此不建议使用)。建议的方法是生成一个路径,例如 media.example.me/XYZ/stylesheets/screen.css,并为每次部署将此XYZ更改为不同的数字(时间戳/ epoch会这样做) )。通过这种方式,在每次部署时,您都只需使HTML和其他文件无效即可,它们是新路径,并且将重新加载。这种技术通常称为对URL进行指纹识别。

Another important thing to also handle here is the versioning the CSS/JS etc. You might make frequent changes to your CSS/JS. When you make any change typically CDNs take 24 hrs to reflect. (Another option is invalidating files on CDN, this is but charged explicitly and is discouraged). The suggested method is to generate a path like "media.example.me/XYZ/stylesheets/screen.css", and change this XYZ to a different number for each deployment (time stamp /epoch will do). This way with each deployment, you need to invalidate only the HTML and other files are any way a new path and will load fresh. This technique is generally called finger-printing the URLs.

更多推荐

设置不带S3的Amazon Cloudfront

本文发布于:2023-11-23 16:39:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622157.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不带   Cloudfront   Amazon

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!