X-Accel-Redirect not redirecting to named locaiton

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

X-Accel-Redirect not redirecting to named locaiton

vergil
I have the below config, calling /v2/test/status calls the
http://test.svc.cluster.local:9080/status.  But the named location `acreate`
is not being called. http://test.svc.cluster.local:9080/status  does return
`X-Accel-Redirect: @acreate` in response header.

location @acreate {
    internal;
    return 200 "testing";
   
   }

location ~ /v2/test(.*)$ {
      proxy_method GET;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header content-type "application/json";
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-NginX-Proxy true;
      set $serv  <a href="http://test.svc.cluster.local:9080$1;">http://test.svc.cluster.local:9080$1;
      proxy_pass  $serv;
}

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,288509,288509#msg-288509

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: X-Accel-Redirect not redirecting to named locaiton

Francis Daly
On Tue, Jun 30, 2020 at 09:19:40PM -0400, latha wrote:

Hi there,

> I have the below config, calling /v2/test/status calls the
> http://test.svc.cluster.local:9080/status.  But the named location `acreate`
> is not being called. http://test.svc.cluster.local:9080/status  does return
> `X-Accel-Redirect: @acreate` in response header.

The below config works for me, as the tests show.

Can you show the results of similar tests, to see where the difference is?

Configuration:

==
  server {
    listen 6060;
    location @named {
      return 200 "In @named location 6060\n";
    }
    location ~ /v2/test(.*)$ {
      set $serv <a href="http://127.0.0.1:9080$1;">http://127.0.0.1:9080$1;
      proxy_pass $serv;
    }
  }
  server {
    listen 9080;
    return 200 "In 9080, request was $request_uri\n";
    add_header X-Accel-Redirect @named;
  }
==
Test request/response pairs:

==
$ curl -i http://127.0.0.1:9080/direct
HTTP/1.1 200 OK
Server: nginx/1.17.2
[snip]
X-Accel-Redirect: @named

In 9080, request was /direct

$ curl -i http://127.0.0.1:6060/v2/test/status
HTTP/1.1 200 OK
Server: nginx/1.17.2
[snip]

In @named location 6060
==

You indicate that you don't get the response that you want.

What response do you get?

Cheers,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: X-Accel-Redirect not redirecting to named locaiton

vergil
Thank you Francis Daly. Jumping to named location worked in my env also.  
I have another issue now:
I want to pass the response body of
http://test.svc.cluster.local:9080/v2/test/* apis to named location
`acreate` which does proxy_pass to another micro-service (which takes the
response of /v2/test* api as payload). I learnt that `body_filter_by_lua`
does not work with internal redirects, are there any other options to do
this?

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,288509,288626#msg-288626

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: X-Accel-Redirect not redirecting to named locaiton

Francis Daly
On Wed, Jul 08, 2020 at 03:52:14AM -0400, latha wrote:

Hi there,

> I want to pass the response body of
> http://test.svc.cluster.local:9080/v2/test/* apis to named location
> `acreate` which does proxy_pass to another micro-service (which takes the
> response of /v2/test* api as payload). I learnt that `body_filter_by_lua`
> does not work with internal redirects, are there any other options to do
> this?

I don't know; and I have not tested it; but the "Subrequests Chaining"
example using njs on http://nginx.org/en/docs/njs/examples.html does
seem to use some of "reply.responseBody" from the first subrequest as
part of the second subrequest.

Maybe that can be adapted to what you want?

Good luck with it,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx