S
S
Sergey Sokolov2017-06-26 22:27:33
Nginx
Sergey Sokolov, 2017-06-26 22:27:33

How can nginx redirect a request based on JSON content?

NGINX accepts POST requests containing small JSON. Depending on the values ​​of the two fields, requests must be redirected to one or the other upstream.
For example, POST requests come with a body like or . You need to send those from A to , and those from B - to How can this be done by NGINX, without running third-party php scripts? It seems that you can somehow use Lua scripts, but I have never come across this. {"type":"A","data":{...{"type":"B","data":{...https://hostA.domain.tldhttps://hostB.domain.tld

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2017-06-26
@sim3x

https://github.com/calio/form-input-nginx-module
but more flexible to write in lua

B
Boris Korobkov, 2017-06-26
@BorisKorobkov

No. Nginx does not parse the request BODY. Pass type as a post parameter from the front.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question