'How create Nginx redirect if php send 404 error

i have a project and this project installed on few servers, he has one code, example:

Server "A" => Project "A"
Server "B" => Project "A"

Project has bundle for create caching and crop images, example:

http://projectA.com/media/cache/50_50/fileA.jpg

If cache not exists, he will be create and after it will be all ok. Example for Server B:

http://projectB.com/media/cache/50_50/fileB.jpg

But, Project "A" on a server "B" can know about "fileA.jpg" through database, and if we will be open through "http://projectB.com/media/cache/50_50/fileA.jpg" we will have error 404 "Cache cannot create because file does not exists" And how in this moment we can create nginx config for this situation?

Config on "ServerB"

location @liip_imagine {
    

    #proxy_intercept_errors on;
    proxy_set_header Host $http_host;
    #proxy_set_header X-Real-IP $remote_addr;
    #proxy_set_header X-Forwarded-For $remote_addr;
    proxy_pass https://projectA.com;

    # rewrite ^.*$ /bucket/$arg_member/$arg_imgname break;
    rewrite  ^/(cache)/(media)/resolve/(.*)$ https://erc.ua/$1/$2/$3;
   # error_page 404 @liip_imagine_404;
   # return 302 https://example.com/cache/media/$1/$2;
}

location ~ ^/(cache)/(media)/(.*)$ {
    if (-f $request_filename) {
       break;
    }

    try_files /var/www/html/files/$3 @liip_imagine;
}

but this rules all time rewrite to "ServerA"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source