Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.