Jump to content

HOW TO: Recommended Cloudflare Settings


pir8radio

Recommended Posts

darkassassin07

If you forward a different wan port to your server (8096 for example), can you reach your server through that?

 

My previous internet connection blocked hosting on port 80, but every other port I tried worked. I've heard of other ISPs blocking some incoming ports but not others.

Edited by darkassassin07
Link to comment
Share on other sites

vaise

Also, had your isp changed to cgnat?  As that would also cause this as you can’t port forward with cgnat.

 

cf with proxy dns ticked will only forward 443 so so all testing with that turned off.

Link to comment
Share on other sites

crusher11
4 minutes ago, vaise said:

Also, had your isp changed to cgnat?  As that would also cause this as you can’t port forward with cgnat.

They use CGNAT by default, but I specifically opted out when signing up. That my IP remains the same as what I set up in CloudFlare indicates they haven't changed anything on me.

4 minutes ago, vaise said:

cf with proxy dns ticked will only forward 443 so so all testing with that turned off.

I'm not sure I follow. If I'm testing IP:PORT then CF settings are irrelevant, surely? Either way, yes, it's currently DNS only.

Link to comment
Share on other sites

vaise

Cf does proxies only 80 and 443 traffic I thought.  Hence turn off proxy until you get comms to your open port working.

Link to comment
Share on other sites

vaise

Could they have turned cgnat back on by accident or design?

Link to comment
Share on other sites

crusher11
40 minutes ago, vaise said:

Could they have turned cgnat back on by accident or design?

I still have the same IP address, so it seems unlikely.

Link to comment
Share on other sites

vaise

Gotta be the port forward is not working then.  Have you tried restarting your router?

Link to comment
Share on other sites

vaise

Is there any sort of firewall active on your emby server?

Link to comment
Share on other sites

crusher11
3 minutes ago, vaise said:

Is there any sort of firewall active on your emby server?

I'm not sure? It's running through CloudFlare and NGINX, I don't think there's anything else in there.

Link to comment
Share on other sites

unisoft

Are the exclusions still similar to:

yourdomain.net/*videos/*/*

yourdomain.net/*items/*/images/*

as when I look in emby's server logs I see paths which makes me think it should be:

 

yourdomain.net/emby/*videos/*/*

yourdomain.net/emby/*items/*/images/

Anyone who knows, would be grateful :)

Link to comment
Share on other sites

vaise

Would that not depend on if you are using subdomains or not ?

Mine are :

image.png.676ab677c7dc1f5696dd3fdb26bc2d4a.png

Link to comment
Share on other sites

vaise
On 06/03/2024 at 01:13, unisoft said:

Are the exclusions still similar to:

yourdomain.net/*videos/*/*

yourdomain.net/*items/*/images/*

as when I look in emby's server logs I see paths which makes me think it should be:

 

yourdomain.net/emby/*videos/*/*

yourdomain.net/emby/*items/*/images/

Anyone who knows, would be grateful :)

Its only video you are excluding - and in my experience, if this is not excluded and goes through CF cache - they things take 20-30 seconds to start. 

This was from testing when these had to be changed with @pir8radio a long time ago now (year back).  He ran tests on my system, viewed the chrome debug, and we made the changes i=until the cache was not there for videos, then the files played back immediately.

That said - I have swag sitting ready to take over in case I am blocked.....

Link to comment
Share on other sites

vaise

That’s fine.  
But you are not getting any benefit of your emby jpg’s, images etc being distributed to all their end servers so closer to remote users.  

However when I ran with no caching (just a tick box so no need for a different port), I never noticed much of a difference from the users.

Link to comment
Share on other sites

CFC

Yes, I didn't notice much if any difference cached or not cached.

Correct, I can tick to un-proxy, but I like to use their firewall features and filter my incoming connection to CF ip's only on my end.

It's just another option for those who may not be aware.

CFC

 

Link to comment
Share on other sites

vaise
1 hour ago, CFC said:

Yes, I didn't notice much if any difference cached or not cached.

Correct, I can tick to un-proxy, but I like to use their firewall features and filter my incoming connection to CF ip's only on my end.

It's just another option for those who may not be aware.

CFC

 

I did not mean untick the proxy (very bad), but there is a screen to disable all caching - just a switch on what you want cached.  If I think there are CF issues, i click that off, then flush cache and see if any issues still - that's how we found that CF roles slightly changed and the cached files needed updating for emby.

But as you say - it really does not seem to make much, if any difference - in the user poll I did.  

I also swapped to my 'disaster' plan if CF block me - untick the proxy, re-open the 443/80 port forwards (as I use tunnels now) and start up my swag reverse proxy - and still the users did not notice any differences in speed of browsing libs etc.

Caching level :

image.png.9bb8d564ed1e29da635da7c50e919caa.png

 

Link to comment
Share on other sites

  • 1 month later...
HorsePDF

I finally got some time to try and move away from hosting Emby directly and use Cloudflare - I came up with something today that serves nearly all requests via Cloudflare, but goes directly for the actual video streaming, which I posted here:

This works for me because I don't have restrictions on my home internet connection, if you are using CF tunnels to avoid CGNAT then this won't help - but if you just want to use Cloudflare auth/caching/security then it may be valuable for you.

 

Link to comment
Share on other sites

vaise
2 hours ago, HorsePDF said:

I finally got some time to try and move away from hosting Emby directly and use Cloudflare - I came up with something today that serves nearly all requests via Cloudflare, but goes directly for the actual video streaming, which I posted here:

This works for me because I don't have restrictions on my home internet connection, if you are using CF tunnels to avoid CGNAT then this won't help - but if you just want to use Cloudflare auth/caching/security then it may be valuable for you.

 

Nice 1.  A bit technical for most - but great nonetheless..

Link to comment
Share on other sites

KegTapper

Great write-up!!!!

I'm on cgnat and still plugging away with a tunnel averaging 150gb per month. 

Link to comment
Share on other sites

  • 1 month later...
shoodidagen

Hi @pir8radio

I think there have been some changes since this was last updated. There's no longer a section 2.8 on Cloudflare's TOS (only goes to 2.7 then onto section 3).

Some of the options have been Deprecated, and I can't work out how to configure the rules as there are Lots of options to choose from (Page Rules is also Deprecated).

Are you able to help me please?

Thank you

 

 

On 05/11/2021 at 16:59, pir8radio said:

Cloudflare and emby   cfemby.png.d790f6f093c32d10633103d6c9cb7097.png.4258c0fcd5367d6bda717937d64a26cb.png

Config Version                                     1.0.0
Last Update 02-25-2022
Update by Pir8Radio                                                                  

 

** UPDATE:  I AM HEARING OF EMBY USERS GETTING VIDEO FILES BLOCKED WHEN USING CLOUDFLARE (FREE TIER).  IF THIS IS THE CASE, I NO LONGER RECOMMEND USING CLOUDFLARE.   

Even with the cache bypass rules, your video still passes through their system and is technically against their TOS.   Use CloudFlare at your own risk if you choose to continue.   I'll update if I get more info.  Please post in this thread if you find you have video loading/playing/downloading issues while using cloudflare or have received an email from them about this.  

 

MESSAGE FROM CLOUDFLARE:  Free, Pro, and Business Plans serving videos or a disproportionate amount of non-HTML content can be in violation of Section 2.8 of the Self-Serve Subscription Agreement (TOS).

 

This will turn into a full Cloudflare how-to.  Others are welcome to edit this or PM me with suggestions..   However right now I'm just going to post some recommended settings for people who already have Cloudflare setup.

 

There are a few cloudflare settings that break emby, some break it in obvious ways, some only certain apps in certain situations..   These are the settings I found that work well as of today. I'll try to maintain this post and update the header info should new features come out, or the community discovers better settings than these. 

As of today, these are the settings available to us in Cloudflare FREE account:

image.png.c62d4117da5424a9fe8fa0d14cbc4033.png

 

First disable the two main things that will break emby,  go to the "Speed" tab then "Optimization" sub-tab.

DISABLE Auto Minify and Rocket Loader!  (screen shots are in the recommended state)

image.png.e4ea1085bafb5508cde296c4245feb27.png

image.png.1d50d37296be1903752adccd7fe3b9ba.png

 

 

Other options on this settings page are optional to enable, I suggest enabling Brotli compression.   It's a good thing. 

image.png.fa6dfe5a3ff63db7900acbfc1c5fb49d.png

 

Now head over to the "Caching" tab and select the "Configuration" sub-tab.

Set your Caching settings as shown below. 

image.png.48117436370ea49b18fb614d8bfcc1df.png

 

THIS IS OPTIONAL:

image.png.1ea56c5f2ceb3d5072ff0b29a651ac6c.png

Other settings in this settings tab are optional to whatever you like..   I have "Always Online" enabled, its kind of a neat feature that caches as much of your emby server as it can in case your server is down, users will at least see an emby splash screen, that's usually about it..  but its something...     kind of useless otherwise..   Handy if you have other websites, it will totally cache normal html websites and users can continue to use your cached site when you have a web server outage. 

 

Next head over to the "Rules" tab.

Create these two rules:

Rule #2 here we will bypass caching 99% of all video.   Caching the video will actually slow down the client experience.  It screws with the chunks and often times has to fully cache 1 chunk before cloudflare sends it to the client, causing playback delays. 

Rule #3 here will cache all images on the edge servers for 30 days.   We need this rule, because cloudflare only caches known file urls, like    picture.jpg or poster.png  emby serves up webp images with NO EXTENSION so cloudflare doesn't know to cache these items.   But 99% of emby images come from the /items/XXXXXX/images directory so we will just force cache everything that comes from this URL,  it should be only images.        Keep in mind when you enable this it can take some time to build up cache..   emby serves up different sized images based on browser screen size, apps, etc..   so if you load a page that is minimized to a small window on your desktop emby will serve smaller sized images, if you make your browser full screen, now emby will serve up larger images and those images may load slow the first few times until they get cached too.        Go below this screenshot and I'll show you how to check if caching is working.  

image.png.37471cae6cb19fad22ae590d2824652d.png

 

Check to see if Cloudflare Caching is working

Well, how do you know Cloudflare is doing its thang'?    Use a browser like chrome,  or the new Microsoft edge (which is just a rebranded chrome).  Open the browser, right click in the browser window and go down to "Inspect" (there is an F key for this too I forget what it is, I should add that here lol).  Once the dev window pops up adjust it so you have a good view on the right, click the "Network" tab,  hit the reload button on whatever page you are on so some info populates on the right dev screen.  You should see something similar to this:

image.thumb.png.7bd3101b12ff7aa244ac2e3f8b711bd6.png

Right click on the table header (Name, Method, Status, Protocol)   anywhere, just right click the "Name" one.   Go down to "Response Headers"  then "Manage Header Columns".   A little window will pop up hit "Add custom header..."  and then add this header:   cf-cache-status 

Now select the little sub tab that says "all" 

 image.png.41e14a920605bc5b188080be6959ee9c.png

 

now surf your way to your emby server,    and you should see something like the below screenshot.   

Hit is well..... a hit!   this image came from cloudflare and was never requested from your emby server, saving you from sending this image to the client, saving time and bandwidth. 

MISS is also kind of obvious,  it was a miss, either due to never being cached yet (first time Cloudflare has seen this image or document) if you hit refresh a few times, cloudflare will then cache it and it will turn to HIT. 

BYPASS I'm actually not sure why my server is returning server 500 errors below, this image is being called for by emby clients but the server has no image to serve, but usually you should only see BYPASS on playing video's if your rules above are correct.   Or in my case, a server error will not be cached. 

DYNAMIC this is also a NO HIT response..  this is usually due to Cloudflare knowing this resource changes a lot and doesn't want to cache it so your clients don't get served stale data, or its a video, websocket, or some other format Cloudfare's great automated intelligence deems it should not be cached. 

Capture.thumb.PNG.4672292e3b00c2c1be660222f7205c86.PNG

That is the basics that will save you a lot of headache and blaming emby for things not working..    There are lots of cool options to enable outside of these basic settings above, ask questions here, send ideas that maybe I have missed that work great for you..    I just wanted to throw this up due to a lot more of you guys using Cloudflare. 

 

In the end you should start to see more "HIT" responses...   and a noticeably faster loading time for the clients, less bandwidth usage for your emby server,  and everyone is happy..   Well.....  within reason....

image.thumb.png.cfed30d81032e87d44285b463029cbf3.png

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...