Welcome! Log In Create A New Profile

Advanced

Re: Nginx postgres problem

March 05, 2014 05:21PM
Hello Yichun,

The use case I am trying to test is the client sends a request to nginx server with some parameters say "/a/b/c/d":
http://NginxHost/a/b/c/d

Depending on the parameters a,b,c and d I will get the IP and port of the destination server (by communicating with postgres) where the request must be redirected to ie the new url is of the form:
http://IP:port/a/b/c/d.

Using both ngx.redirect and nginx.exec() are giving errors.
I tried to redirect the url to "www.google.com" using ngx.redirect inside rewrite_by_lua. Even I get the same error.

You had mentioned that " redirects in a subrequest won't affect its parent requests." Does that mean that I cannot change the url inside the rewrite_by_lua module?

I cannot use http rewrite module as this will be executed before the rewrite_by_lua code is executed.

Please suggest what can be done to redirect the parent url to new url.

Thank you,
Arun


ERROR LOG:

CODE:
location /postgresrewrite
{
rewrite ^ "http://www.google.co.in";
}
ngx.exec("/postgresrewrite");
LOG:
2014/03/05 22:59:42 [error] 8129#0: *374 lua entry thread aborted: runtime error: [string "rewrite_by_lua"]:32: attempt to call ngx.exec after sending out response headers
stack traceback:
coroutine 0:
[C]: in function 'exec'
[string "rewrite_by_lua"]:32: in function <[string "rewrite_by_lua"]:1> while sending to client, client: xx.xx.xx.xx, server: localhost, request: "GET /tenantservices/ArunTenant.com/Service1/13717e3b-c32d-4172-a316-74857b1237e1/httpSoapProvider HTTP/1.1", host: "yy.yy.yy.yy"

CODE:
return ngx.redirect("http://www.google.co.in");
LOG:
2014/03/05 22:23:05 [error] 5397#0: *366 lua entry thread aborted: runtime error: [string "rewrite_by_lua"]:32: attempt to call ngx.redirect after sending out the headers
stack traceback:
coroutine 0:
[C]: in function 'redirect'
[string "rewrite_by_lua"]:32: in function <[string "rewrite_by_lua"]:1> while sending to client, client: xx.xx.xx.xx, server: localhost, request: "GET /tenantservices/ArunTenant.com/Service1/13717e3b-c32d-4172-a316-74857b1237e1/httpSoapProvider HTTP/1.1", host: "yy.yy.yy.yy"
SubjectAuthorPosted

Nginx postgres problem

arunhMarch 04, 2014 10:15AM

Re: Nginx postgres problem

Yichun Zhang (agentzh)March 04, 2014 06:20PM

Re: Nginx postgres problem

arunhMarch 05, 2014 11:39AM

Re: Nginx postgres problem

Yichun Zhang (agentzh)March 05, 2014 03:00PM

Re: Nginx postgres problem

Yichun Zhang (agentzh)March 05, 2014 03:04PM

Re: Nginx postgres problem

arunhMarch 05, 2014 05:21PM

Re: Nginx postgres problem

Yichun Zhang (agentzh)March 05, 2014 05:34PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 128
Record Number of Users: 7 on March 06, 2014
Record Number of Guests: 229 on August 01, 2014
Powered by nginx    Powered by FreeBSD    PHP Powered    Powered by Percona     ipv6 ready