I
I
Ivan2019-08-28 02:18:10
Nginx
Ivan, 2019-08-28 02:18:10

How to calculate md5 from url path in Nginx without query args (needed for caching)?

The algorithm is as
follows: 1) we consider md5 or any other hash from /product/mp3501
2) we take the first 3 characters 5B3
3) we redirect the request to the directory with the 5B3 file already prepared by the backend /product/mp3501/index.html
PS
As I understand it, in one directory there are not it's worth trying to create ~700000 subdirectories in the first nesting level, so I'm trying to make several levels of nesting.
There is another option instead of the file system in redis to put pages and read them with nginx (ready for criticism)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2019-08-28
@Lynn

https://github.com/openresty/lua-nginx-module/blob...
nginx.org/en/docs/njs/reference.html#crypto
In 99%, some of this already exists or is easily added.

D
Danil Sapegin, 2019-08-28
@ynblpb_spb

And why not use the regular nginx caching, which pulls the back once and neatly decomposes the cache as it should and monitors its state?
Or in your case, the back is engaged in generating statics, you arrange the files into directories in advance and want nginx to "smartly" pull them?
In this case, I would write the simplest router in any programming language, in which I would read the md5 cache, read the necessary file from the disk and give it to nginx, and nginx, in turn, would cache this response and store the cache.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question