How to check whether the file on the server(nginx)?

Have a server where nginx takes requests.

Sometimes requests come in http://*server_name*/files/images/1.ipg

ngixn should check whether there is server01 in this file, and if not - to get the same file from server02

Long time tested, but did not get set up that way.

I tried something like this:
location ~ /files / * {
 proxy_pass http://server01.ru ;
 if (!-f $request_filename) {
 proxy_pass http://server02.ru ;
}
 }


Also tried try_files, but have not found how to check the data on the remote server.
June 10th 19 at 16:56
3 answers
June 10th 19 at 16:58
Solution
check will not work, but you can send a request to a remote server and check
pseudocode:
location ~ /files / * {
 error_page 404 http://server2/.....;
 root /var/www/static/images;
}

The only. I'm not sure you can specify a different domain in the Directive, but if not, this can be solved by local url with redirect or rewrite. - judging by the documentation - you can.

UPD:
By the way, according to the documentation using "try_files" it's the same possible to make
nginx.org/en/docs/http/ngx_http_core_module.html#t...

In the following example,

location / {
 try_files $uri $uri/ @drupal;
}
the try_files directive is equivalent to

location / {
 error_page 404 = @drupal;
 log_not_found off;
}
OK.
A little stupid question:
What did I do that portforwarding:
location / {
 root /var/www;
 autoindex on;

 if (!-f $request_filename) {
 charset utf-8;

 proxy_pass <a href="http://*SERVER*:80;">http://*SERVER*:80;</a>
 "proxy_redirect" off;
 proxy_set_header Host $Host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_set_header X-Forwarded-Proto $scheme;
}
 }


It was a test of nginx says:
nginx: [emerg] ""proxy_redirect "" directive is not allowed

Config test, but the error don't understand(

########################
UPD:
Understood, not proxy settings if stick) - Kaycee.Gulgowski21 commented on June 10th 19 at 17:01
June 10th 19 at 17:00
June 10th 19 at 17:02
location / {
 proxy_pass http://a.a.a.a;
 proxy_intercept_errors on;
 error_page 404 = @server2;
}

location @server2 {
 proxy_pass http://b.b.b.b;
}

Find more questions by tags NginxLinux