Nginx allows enabling next upstream for the following seven retryable error codes
  • 403 Forbidden
  • 404 Not Found
  • 429 Too Many Requests
  • 500 Internal Server Error
  • 502 Bad Gateway
  • 503 Server Unavailable
  • 504 Gateway Timeout
When upstream returns 404, return a 200 response with a not-found image

You can use proxy_intercept_errors to achieve this.\n> When proxy_intercept_errors is enabled, requests with upstream response codes >= 300 can be further handled via the error_page directive.

location /ih {
        proxy_pass http://ihBackend;
        proxy_intercept_errors on;
        error_page 404 = /404.html;
}
location = /404.html {
        alias html/404_not_found.html;
}