Hi, I wanted to host a personal Lemmy instance online (for just myself, I don’t think I can take the upkeep for other users - please let me know if this is not possible) and wanted to understand how to “attach” a CDN service to it.
The idea behind doing this is that I’m in the US but I’m looking to host a server in Europe. I am looking into Cloudflare’s free CDN service, but it would be great if someone could point me towards how I can configure this setup to speed up the loading time for my Lemmy instance (which is going to be far away from me, geographically).
I would also like to know about your setups and how you have hosted Lemmy.
Thanks!
Thank you for your comment!
I am opting for the very low cost providers like Racknerd and CloudServer (see: $1 VPS offerings) - which host most of their servers outside the US.
Thank you for the explanation, I would like to know more about the “effort” from Lemmy’s side to let Cloudflare cache content before it is requested.
Could you explain this point a bit more? Why would Cloudflare need to control DNS for my domain? How is this linked to them proxying my traffic? I’ve been trying to understand this for a bit now - how does having CF’s own nameservers let CF proxy my traffic?
I was also considering hosting Lemmy in my own network, but I can’t seem to find any guides on which ports to forward - if I could just find a decent guide on the networking required to host Lemmy I might even do it on-prem.
Thanks a bunch!
basically, lemmy would need to have a way tobe able to tell where (geographically) content will be consumed. for your case it’s easier since you’re the only client and presumably you don’t move much, but for larger instance not only is this a ful time job in large internet companies, but lemmy isn’t programmed to know where you live, for privacy. on top of that, cloudflare tries automatically to cache the appropriate content, but as a general-purpose company they have no interst in actually allowing you to tell them what to cache and how to cache it. discord gets to do it because they own both the app and the CDN, you own neither.
they need to be your DNS servers because they need requests to your website to contact them, and they’ll do the routing themselves. for example, assume the caching problems we talked about are magically resolved. if a client makes a dns request and gets your ip, it will hit you ip and completely bypass cloudflare. in theory, you could change your dns records to point to cloudflare’s server instead, but that means you need to do that every time their ip chnages and for every region, it’s just not efficient. so instead they get to be the authority, and they decide exactly what servers are hit and when, and from where. this is why when using cloudflare, you are protected from DDoS attacks, since only cloudlfare knows your IP. that said, i have been hosting various things for years from my residential IP and have never had a problem (though i am cheating by having more up/down than most of the world has down/up, so any one attacker is just bottlenecking themselves).
Using Cloudflare nameservers helps to proxy your traffic because if proxying is enabled (“orange cloud”) those servers aren’t handing out your IP address to people who request your domain, they’re handing out addresses belonging to Cloudflare machines near the visitor instead. They have machines in data centers all around the world, and they would like the traffic to end up in the data center closest to where it’s needed.
Doing that means they can do stuff like reduce cross-region network traffic: for instance, if your VPS is in Europe but a bunch of visitors from the US suddenly request a certain image on your site (because you’ve just posted to a popular community, perhaps), they only need to have that image data cross the Atlantic once before they can serve it up many times in the US. Besides saving bandwidth that also allows it to be served faster to most visitors, because most requests for it are effectively served from a local data center instead of from one on another continent. They’ll also continue to be able to serve your image even when your VPS is down for whatever reason, as long as it’s already in cache.
(Most of that is probably oversimplified and but hopefully that clarifies it a bit)