Nginx postgres problem

arunh nginx-forum at nginx.us
Wed Mar 5 16:39:06 UTC 2014


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 } );
           ';

}

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,248077,248147#msg-248147



More information about the nginx mailing list