nginx: handling 404 with error_page
- by ytw
Originally, I have something like this in the nginx.conf file.
location ^~ /test_api {
types { application/json json; }
root /usr/local/www/data;
rewrite "/test_api/(.*)" /api_response/test_api_$1.json break;
error_page 404 /api_response/unknown_request.json;
}
When a requested resource is not found locally, unknown_request.json (default response) is returned correctly.
Then I had to change the rewrite to point to a remote server as follows:
rewrite "/test_api/(.*)" $scheme://www.somedomain.com/test_api_$1 break;
It doesn't return unknown_request.json (default response) anymore even though the remote server returns a 404.
Is there a way to continue to return unknown_request.json to the client when the remote server returns a 404 assuming the remote server can't be changed to return unknown_request.json?
Thanks very much.