Gershon-A / nginx-lua-rewrite-request

The following example is to rewrite incoming requests by adding some additional data then send a new request to the destination.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Test

Reverse proxy

cd nginx-lua-request-capture
docker-compose -f docker-compose.yml up -d

logger

cd logger
docker-compose -f docker-compose-loger.yml up -d

Send request

curl -i http://localhost:8082/ -H 'content-type: application/json'   -d '{    "level":"INFO",    "source":"Gershon",    "message":"Received response 404",    "client_secret":"secret",    "user_key":"my_key" }'

How Tested:

curl -i http://localhost:8082/ -H 'content-type: application/json' -d '{ "level":"INFO", "source":"Gershon", "message":"Received response 404", "client_secret":"secret", "user_key":"my_key" }'

http://localhost:8082 - nginx that acts as a reverse proxy to another nginx that acts as logger

http://localhost:8082 nginx rewrite body request and append additional data "client_ip":"172.19.0.1" before sending to destination (logger)

The request received at the end (logger): docker logs -f logger_nginx_1

"body":"{\"user_key\":\"my_key\",\"client_ip\":\"172.19.0.1\",\"message\":\"Received response 404\",\"level\":\"INFO\",\"source\":\"Gershon\",\"client_secret\":\"secret\"}"

About

The following example is to rewrite incoming requests by adding some additional data then send a new request to the destination.

License:Apache License 2.0


Languages

Language:Lua 99.8%Language:Dockerfile 0.2%