How to cache files behind secure nginx links?


#1

I have a file that secured behind nginx proxy link.
The url schema is simillar to:
https://domain.com/file.txt&token=cccc$mdf=jddjdhhh
The secure link is changable every time depend on usr location and request time.
I made a curl to the upper link from my PC and wait till cloudflare cache the file , then i request a new secure link that acutally lead to the same file and curl the new link. I found that cloudflare said that the file is missing in cache while it is the same file just different link pattern.
How i tell cloudflare to cache file with url:
https://domain.com/file.txt
regarding the parameters after that link?
Thanks.


#2

That should be possible with a page rule and setting the caching level to ignore the query string.

Unfortunately some areas of Cloudflare currently return an error, so I cant post a screenshot.


#3

Thanks for reply.

Assuming the generated secure link is:

https://domain.com/files/file.txt?md5=cw6nflZRwn1PGPowqf6MBw&expires=1548497943

Here is the pattern i use to find the last parametres:

/(?<=\.txt)([^\n]+)/

Now, how i tell cloudflare to ignore the last characters in url using the upper patteren?

Thanks.


#4

/files/* should work. It will apply to all files in that directory though, only only TXT files.


#5

That simple enough @sandro .

So what is the next steps after making this regex?

How to tell cloudflare to cache that file no matter how the ?md5=cw6nflZRwn1PGPowqf6MBw&amp;expires=1548497943 change?


#6

One a second thought, the issue would be that the file is always served regardless of whether the code is valid or not and you probably dont want that.

If you really want to outsource that to Cloudflare your only option might be implementing a Cloudflare worker.


#7

That is come across my thought two.

Any documentation about how to implement cloudflare workers?

Or do you have a simple guide about it?


#8

#9

@sandro , thank you very much for your help and your time.

I will take a look to documenations .

regards.


closed #10

This topic was automatically closed after 31 days. New replies are no longer allowed.