帮助理解 CDN 的设置吗?
以下是我在搜索中找不到的几个问题:
当您的网站添加CDN服务时,您是否仍然在源服务器上维护/创建本地动态文件并将CDN指向该位置,设置http规则,并让他们自动上传如果他们还没有托管呢?
假设我的源服务器上有一个头像上传表单,在裁剪功能之后,我是否将保存图像设置到本地目录或 CDN?
我的另一个问题是,如果您先在本地保存文件并等待 CDN 拉取它们,您如何为页面编写代码以了解差异?您是否使用类似的东西
// $filename = 'images/image.jpg';
function static_file($filename) {
$cdnfilepath = 'http://cdndomain.com/';
if (fopen($cdnfilepath.$filename, "r")) {
return $cdnfilepath.$filename;
} else {
return $filename;
}
}
,或者您是否只是将您希望 CDN 直接托管的每个动态创建的文件放入 CDN?
如果有人知道这方面的好教程会很有帮助。抱歉,如果其中有任何内容已被涵盖,但我一直在寻找没有明确的答案......
Here's a few questions I cannot find in search:
When adding CDN services to your website, do you still maintain/create local dynamic files on your origin server and point the CDN to that location, set a http rule, and have them upload it automatically if they aren't hosting it yet?
Let's say I have an avatar upload form on my origin server and after a cropping function, do I set the save image to the local directory or to the CDN?
The other question I have is if you save files locally first and wait for the CDN to pull them, how do you code for the page to know the difference? Do you use some thing like
// $filename = 'images/image.jpg';
function static_file($filename) {
$cdnfilepath = 'http://cdndomain.com/';
if (fopen($cdnfilepath.$filename, "r")) {
return $cdnfilepath.$filename;
} else {
return $filename;
}
}
Or, do you just PUT every dynamically created file that you would like the CDN to host directly to the CDN?
If anyone knows a good tutorial on this that would helpful. Sorry if any of this has been covered but I having been searching with no clear answers...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有时没有直接上传到 CDN 的直接方法。
例如,使用 AWS,您必须 PUT 文件,这意味着它仍然需要暂时上传到您的服务器。我所做的是将文件上传到临时目录,然后运行一个 cron 脚本,将文件放到 AWS 上,以免导致最终用户的上传过程花费更长的时间。
Sometimes there's no straight-forward way of uploading directly to your CDN.
For example with AWS you have to PUT the file, which means it still has to be uploaded to your server temporarily. What I do is upload the files to a temp directory then have a cron script run that PUT's the files onto AWS, so as not to cause the upload process to take any longer for the end-user.