Parse JSON POST request into nginx variable

How can I read a POST request body which is JSON and get a property? I
need
to read a property and use it as a variable in proxy_pass.

Pseudo code:

$post_request_body = ‘{“account”: “test.mydomain.com”, “more-stuff”:
“here”}’;
// I want to get
$account = “test.mydomain.com”;
proxy_pass $account/rest/of/url/here;

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

justink101 Wrote:

How can I read a POST request body which is JSON and get a property?
I need to read a property and use it as a variable in proxy_pass.

Pseudo code:

$post_request_body = ‘{“account”: “test.mydomain.com”,
“more-stuff”: “here”}’;
// I want to get
$account = “test.mydomain.com”;
proxy_pass $account/rest/of/url/here;

Hello,
I’v wrote a simple configuration example with LUA script to process
posted
JSON body and based on KEY/Value take a different action:
/you can find it here:
http://www.energy-bg.org/processing-json-with-nginx-and-lua/

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

There is a form input module you can use to parse POST body into a
variable:

https://github.com/calio/form-input-nginx-module

However this will not get JSON data. For this you make want to look into
leveraging the nxin Lua module in conjunction with the Lua cjson module:

http://wiki.nginx.org/HttpLuaModule
http://www.kyne.com.au/~mark/software/lua-cjson.php

The openresty package combines the above two modules into one package :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs