K
K
Konstanin Prog2018-04-20 15:03:22
Nginx
Konstanin Prog, 2018-04-20 15:03:22

How to emit static or generate stats with nginx?

There is a certain static resource, storage... static.site.com
It contains, as it were, an "eternal cache" of some dynamic files.
For simplicity, in the application, the link immediately goes to the address static.site.com
But if the file was never requested there, it is not, and we must generate it. server static knows nothing about scripts and has no access to php.
I implemented this quite standard solution:

if (!-e $request_filename) {
      rewrite ^/dir/file(.*)_(.*).ext https://api.site.com/generate?a$1&b=$2 break;
    }

The file is successfully generated, however, even after it appeared already at static.site.com/dir/fileX_Y.ext, it still continues to redirect the request to api.site.com, I can’t understand the reasons.
I also tried the option to wrap everything in location / dir / and go from it, but it did not help.
I don’t cite the rest of the config lines, since they have nothing to do with the case. Like text compression and cache settings.
listen 443 ssl http2 if that. There is currently no Location inside the server at all.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
@
@mgyk, 2018-04-23
_

It is not at all clear how the file should appear on the nginx server?
The variant with try_files and a redirect in the absence of a file does not go to another resource and that's it. It won't show up locally.
https://www.nginx.com/blog/nginx-caching-guide/ You need to turn on response caching on the nginx side.

B
Boris Korobkov, 2018-04-20
@BorisKorobkov

if (!-e $request_filename) {
rewrite ...
}

It's better to use try_files
Browser cache

H
Hikmat Abdunabiev, 2018-04-20
@Khikmat

Try like this although not very strong in nginx:

location ~ ^/dir/file(.*)_(.*).ext$ {
        try_files $uri https://api.site.com/generate?a$1&b=$2;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question