Welcome! Log In Create A New Profile

Advanced

Re: Nginx postgres problem

March 05, 2014 11:39AM
Hello Yichun,

Thank you very much for the reply.

I have used ngx.location.capture for extracting the values from postgres database as suggested by you.
I had to make a series of postgres calls so I used content_by_lua along by sharing the varialbes as I had to query tables from multiple databases.

I have now got the needed nodeIP and port ultimately. But I am not able to redirect the url.
I have used rewrite_by_lua in the end to redirect to the new url, but it does not seem to be happening.

If I use http rewrite module again the values of the nodeIP and port would be empty.

Could you please suggest how to redirect to the new url with the extracted nodeIP and port?

Thanks in advance,
Arun

CODE:


location /postgresrewrite
{

rewrite ^ "http://$nodeIP:$port/$inputURI";
}


location ~ ^/tenantservices/(.*)\/(.*)\/(.*)\/(.*)
{
set $inputURI $request_uri;
set $tenantURI $1;
set $serviceName $2;
set $userID $3;
set $endPointName $4;

set $id '';
set $tenantID '';
set $instanceUUID '';
set $nodeIP '';d
set $port '';

set $redirectURL '';

content_by_lua '
res = ngx.location.capture(
"/postgrestenantkey", { share_all_vars = true } );
ngx.var.id = res.body;
ngx.print(res.body);
ngx.print(ngx.var.id);

res1=ngx.location.capture(
"/postgrestenantid", { share_all_vars = true } );
ngx.var.tenantID = res1.body;
ngx.print(res1.body);
ngx.print(ngx.var.tenantID);


res2=ngx.location.capture(
"/postgresinstanceid", { share_all_vars = true } );
ngx.var.instanceUUID = res2.body;
ngx.print(res2.body);
ngx.print(ngx.var.instanceUUID);

res3=ngx.location.capture(
"/postgresnodeip", { share_all_vars = true } );
ngx.var.nodeIP = res3.body;
ngx.print(res3.body);
ngx.print(ngx.var.nodeIP);

res4=ngx.location.capture(
"/postgresport", { share_all_vars = true } );
ngx.var.port = res4.body;
ngx.print(res4.body);
ngx.print(ngx.var.port);
';

rewrite_by_lua '
res5=ngx.location.capture(
"/postgresrewrite", { share_all_vars = true } );
';

}
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: 95
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