Next.js Discord

Discord Forum

CF Proxy Caching Layer for Vercel

Answered
B33fb0n3 posted this in #help-forum
Open in Discord
Hey, imagine a website that is highly dynamic and when it's dynamically generated it costs a lot of database resources. It's a multi tenant app, that hosts websites. The customer websites should be fully static (cached via CF) and purged, when something changed.

DNS
The origin is vercel, that serves all pages fully dynamic. I added the correct DNS entries to cloudflare (CF) and it's working fine (see attached).

Caching Rules
To have the correct caching rules I added the following caching rule expression:
(http.host ne "app.domain.de")

With Eligible for cache and Ignore cache-control header and use this TTL TTL 1 year (maximum)
With also Status code TTL: 200; Duration: 1 year (maximum)

Like that it should cache every customer page for 1 year (app.domain.de is the editor itself. That shouldn't be cached)

Results
As you can see attached I get only redirected (should be fine, because I don't want to see CF, I want to see Vercel when there is no cache).
You can also see, that the cache got bypassed. You can see, that I am not on app.domain.de.

How to configure it correctly?

-- [Allow](https://discord.com/channels/752553802359505017/766433464055496744/1291282080952614933)
@riský also: do you use Cache Reserve or Tiered Cache or both or none?
Answered by B33fb0n3
Fixed the permanent redirect with setting the SSL setting to full instead of flexible. What I did detailedly is described here: https://developers.cloudflare.com/ssl/troubleshooting/too-many-redirects/#flexible-encryption-mode

And the caching working also fine 👍
View full answer

4 Replies

i have no idea how one purges cache on cf.. i just use it for static assets that should never change... that being said i think the new cf pages and nextjs thing should in theory give you that control and with i assume revalidatePath https://canary.discord.com/channels/752553802359505017/752647196419031042/1288855107156447293
Fixed the permanent redirect with setting the SSL setting to full instead of flexible. What I did detailedly is described here: https://developers.cloudflare.com/ssl/troubleshooting/too-many-redirects/#flexible-encryption-mode

And the caching working also fine 👍
Answer
yeah that error its always the case, but i didnt think you had that (well at least i thought you would have made that more clear) 🤣