So files will not synchronise with my system, cloudfront just cache them. Am i true?
3 个赞
pfaffman
(Jay Pfaffman)
2021 年5 月 8 日 12:48
82
Yes. That is correct. The CDN gets from your site just the assets that are requested of it.
Discourse will push to S3 static assets (like css and javascript) as well I uploads.
4 个赞
Pravi
(PK)
2021 年6 月 25 日 19:27
83
Is it possible to use cloudflare rules to cache static assets like css and javascript?
2 个赞
bartv
(Bart )
2021 年6 月 26 日 06:23
84
Yes, we use it that way and it works well. Just be very careful to disable any javascript optimizations. You can see our setup here:
I’m using Cloudflare on my Discourse site and it works fine. You basically route all your traffic through Cloudflare and tell it what to process or cache and that’s it. There are a few things to keep in mind though:
Configure Cloudflare to NOT cache anything (set up exceptions using page rules, see below).
Don’t let Cloudflare touch your Javascript - specifically, turn off Rocket Loader.
I’m not sure about Brotli compression yet, I disabled it.
Set up page rules to cache the avatar and upload …
4 个赞
Pravi
(PK)
2021 年6 月 26 日 07:16
85
Thanks for the response.
I have already added the second and third rule but I didn’t get the first rule. What’s the need for 301 redirect??
2 个赞
bartv
(Bart )
2021 年6 月 26 日 07:41
86
You don’t need it; it’s in the description.
3 个赞
Pravi
(PK)
2021 年6 月 26 日 10:37
87
Thanks for the response. What about the static assets like css and javascripts? Any rule possible for css and javascript??
2 个赞
bartv
(Bart )
2021 年6 月 26 日 10:51
88
I didn’t test that. I’m not sure that would work. At the very least you’d have to clear your Cloudflare cache after every rebuild.
2 个赞
Pravi
(PK)
2021 年6 月 26 日 13:35
89
It’s okay with me to clear the cache after every rebuild. What else would possibly go wrong if I make a rule to cache everything in https://myforum.com/assets/ ? Will this anyway affect user login? If you give a nod, I will test it for a week and report. I still have one unused rule.
2 个赞
MarcP
(MarcP)
2021 年9 月 16 日 02:40
92
Just to clarify, is it correct we do not use this field (as well as CDN URL) if we are using cloudflare CDN?
I have setup cloudflare.template in app.yml as per docs.
Is any further config needed if using cloudflare?
1 个赞
我刚刚成功使用了 StackPath 作为 CDN。效果如预期!
2 个赞
Canapin
(Coin-coin le Canapin)
2022 年7 月 26 日 09:30
95
现在情况还是这样吗?
来自 2019 年:
I’m using Cloudflare on my Discourse site and it works fine. You basically route all your traffic through Cloudflare and tell it what to process or cache and that’s it. There are a few things to keep in mind though:
Configure Cloudflare to NOT cache anything (set up exceptions using page rules, see below).
Don’t let Cloudflare touch your Javascript - specifically, turn off Rocket Loader.
I’m not sure about Brotli compression yet, I disabled it.
Set up page rules to cache the avatar and upload …
看起来我们必须格外小心,并且会失去 Cloudflare 的一些优势。
来自 2020 年:
Cloudflare isn’t broken, your implementation was.
Let’s Encrypt won’t enroll a certificate while CloudFlare is proxying. It prevents the verification from going through.
You can’t use any of their ‘performance’ features with Discourse as it alters the already-minified code.
All CloudFlare can do for you is hide your IP and act as a CDN for your uploads. The benefits are minimal.
来自 2021 年:
Cloudflare is fine - just disable their Rocket Loader feature.
With no configuration effort, it saves half the bandwidth back to my server.
It might be that years ago Cloudflare didn’t work well with Discourse, but it’s not true today. It would be nice if we didn’t keep seeing doubt about it. If anyone has a specific problem, they should start a support thread here describing what’s not working.
那么,Cloudflare 今天与 Discourse 配合是否可靠且高效?禁用“Rocket Loader”功能是否会最小化优势?
我曾考虑从 Stackpath 迁移到 Bunny CDN,但我论坛域名的所有者和前管理员拥有一个 Cloudflare 企业账户(他是 tinyURL 的所有者),他可以免费添加该域名(https://unicyclist.com/t/looking-for-a-decrease-in-the-forum-fees-in-the-future/274858/6)。
所以,我想知道使用 Cloudflare 而不是 Bunny CDN 是否正确、无痛且有效。
2 个赞
Stephen
(Stephen)
2022 年7 月 26 日 11:01
96
如果您的图片很多,那么直接增加固态硬盘的成本将远高于等效的 S3 成本。
S3 需要在其前面放置 CDN 才能具有成本效益,因为您需要按入口和出口付费,但这仍然比仅仅增加高速固态硬盘便宜得多。CloudFlare 可以放在 S3 前面,但资产缓存是唯一可以可靠使用的功能。将 CloudFlare 放在客户端和应用程序服务器之间也会增加跃点数并推高应用程序延迟。它不是万能药。
2 个赞
Canapin
(Coin-coin le Canapin)
2022 年7 月 26 日 11:45
97
我们的图片量不大。内容分发网络(CDN)的目标是让我们的国际用户(主要是美国和欧洲用户)都能快速加载资源。
我们使用 S3,但仅用于存储备份。
1 个赞
Canapin
(Coin-coin le Canapin)
2022 年8 月 25 日 16:38
98
快速提问。更换我们的 CDN 后是否必须重新烘焙?或者仅当 CDN URL 不同时才需要?或者根本不需要?
编辑:或者是否可以通过 Rails 脚本替换已烘焙帖子中的旧 URL 为新 URL?
例如,如果我有一个帖子包含:
<img class="ytp-thumbnail-image"
src="https://f5i4i8k5.stackpathcdn.com/uploads/default/original/3X/f/3/f3bc5ab19cc0394f33fd008e90ca06e081886a0b.jpeg"
title="Riding a unicycle part 76: Sullivan Canyon - Los Angeles"
width="480"
height="360"
loading="lazy"
style="aspect-ratio: 480 / 360;"
>
我能否进行搜索并用 newcdn.unicyclist.com 替换 f5i4i8k5.stackpathcdn.com 的字符串而不破坏任何东西?这似乎 是安全的,但我想确保我所做的事情。
我不介意重新烘焙我所有的帖子,但第一次遇到的问题是,我有数千个嵌入的 YouTube 视频,在重新烘焙过程中,由于向 YouTube 发送了过多请求,我的 IP 被 YouTube 列入了黑名单。
所以,如果有一个比重新烘焙所有帖子更安全的方法,并且可以避免遇到同样烦人的问题,我宁愿选择这种替代方法……
3 个赞
pfaffman
(Jay Pfaffman)
2022 年8 月 26 日 07:25
99
有一个 rake 任务可以进行替换。我认为运行它很安全,也是个好主意。在所有帖子中替换字符串 应该就是你想要的。
2 个赞
Canapin
(Coin-coin le Canapin)
2022 年8 月 26 日 09:52
100
嗨 Jay,
我不确定是否要使用 rake 任务。
CDN URL 似乎存在于 cooked 字段而不是 raw 字段中(除非消息是通过电子邮件发送的)。
据我所知,post:remap 只在 raw 字段中搜索字符串。
end
puts
puts "#{i} posts normalized!"
end
def remap_posts(find, type, ignore_case, replace = "")
ignore_case = ignore_case == 'true'
i = 0
Post.raw_match(find, type).find_each do |p|
regex =
case type
when 'string' then
Regexp.new(Regexp.escape(find), ignore_case)
when 'regex' then
Regexp.new(find, ignore_case)
end
new_raw = p.raw.gsub(regex, replace)
如果替换 raw 和 cooked 字段中的 CDN URL 是安全的,我想我应该使用自定义的 rails 脚本?
2 个赞
pfaffman
(Jay Pfaffman)
2022 年8 月 26 日 15:02
101
你说得对。还有一个 . . . 东西 . . . 会替换数据库中所有字段中的一个字符串。那就是你要找的东西。抱歉,我现在找不到它了。有一些关于从一个 s3 迁移的话题,但似乎没有 #howto。
2 个赞
Canapin
(Coin-coin le Canapin)
2022 年8 月 26 日 15:55
102
谢谢这个线索!
我猜是这个?
DbHelper.remap('from', 'to')
在 Rebaking old posts won't pull new S3 CDN URL after S3 bucket rename - #10 by Brad_Wood 找到
并在以下位置使用:
raise failure_message
elsif s3_objects.size + synced >= local_files.size
log "Updating the URLs in the database..."
from = "/uploads/#{@current_db}/original/"
to = "#{SiteSetting.Upload.s3_base_url}/#{prefix}"
if @dry_run
log "REPLACING '#{from}' WITH '#{to}'"
else
DbHelper.remap(from, to, anchor_left: true)
end
[
[
"src=\"/uploads/#{@current_db}/original/(\\dX/(?:[a-f0-9]/)*[a-f0-9]{40}[a-z0-9\\.]*)",
"src=\"#{SiteSetting.Upload.s3_base_url}/#{prefix}\\1"
],
[
"src='/uploads/#{@current_db}/original/(\\dX/(?:[a-f0-9]/)*[a-f0-9]{40}[a-z0-9\\.]*)",
"src='#{SiteSetting.Upload.s3_base_url}/#{prefix}\\1"
如果这是更改我们的 CDN 服务时,比重新烘焙更安全的选择,那么 howto 确实会很有用。
3 个赞
pfaffman
(Jay Pfaffman)
2022 年8 月 26 日 16:41
103
Coin-coin le Canapin:
谢谢你提供的线索
哦,太好了。感谢告知。我以为这足以让你找到它。很高兴你找到了。
3 个赞