Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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://$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.

share|improve this question
up vote 1 down vote accepted

You've already redirected the request to the remote site; you have no further control over it. The browser will contact the remote site and get whatever response it gets.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.