Modify request body before sending to upstream

abhinanda nginx-forum at nginx.us
Tue Jan 27 07:14:15 UTC 2015


Nevermind my previous post. I solved it finally :)


    location /foo {
        rewrite_by_lua '
            res = ngx.location.capture("/bar", {method = ngx.HTTP_POST, body
= "jjj"})
            res = ngx.location.capture("/bar", {method = ngx.HTTP_POST, body
= res.body})
            ngx.print(res.body)
        ';
    }

    location /bar {
        proxy_pass http://wservers;
    }



[vm ~]$ curl localhost:8080/bar -X POST --data 'hello'
UPSTREAM: hello :UPSTREAM
[vm ~]$ curl localhost:8080/foo -X POST --data 'hello'
UPSTREAM: UPSTREAM: jjj :UPSTREAM :UPSTREAM


Thank you so much!! You saved me a lot of time.

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



More information about the nginx mailing list