4

I have requirement where i need to have a rewrite the response with static context in nginx based on content from the request body say "fruit":"apple",

The nginx location with rewrite config as mentioned below, o

tried referring to nginx conditional proxy pass based on request body content solution, but getting 401 response.

location ~* /getItems/fruits
{
    if ($request_body ~ (.*)apple(.*))
    {
        rewrite ^ /apple.json break;
    }

    if ($request_body ~* (.*)orange(.*))
    {
        rewrite ^ /orange.json break;
    }

    rewrite ^ 401 break;
}

Expected on sending the "fruit":"apple" we should get the apple.json on sending the "fruit":"orange" we should get the orange.json

  • Here https://stackoverflow.com/questions/44245660/nginx-conditional-proxy-pass-based-on-request-body-content people say that such thing requires using lua scripting. – Alexey Shrub Oct 14 '19 at 13:21

0 Answers0