Nginx postgres problem
arunh
nginx-forum at nginx.us
Wed Mar 5 22:21:24 UTC 2014
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"
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,248077,248161#msg-248161
More information about the nginx
mailing list