Nginx: Modify response body with additional request

nginxnode.jsweb-server

I'm looking for a way to modify the body of a response created by some webserver to which I proxy my requests using Nginx:

server {
    listen   80;
    server_name localhost;

    location /myproject/ {
        proxy_pass http://127.0.0.1:8080/myproject/;
        > modify response from http://127.0.0.1:8080/myproject/ before sending
    }
}

It's something like HttpSubModule but with an external program rather than simple text replacement. The modifying program is a Node.js webserver, so I thought about sending the response in a post request. But that's just a brief idea, every kind of approach is highly appreciated.

Best Answer

I've always liked nginx's XSLT processor for jobs like those. Wrote a lengthy blog post on that last year, too - shameless plug: http://ef.gy/using-nginx-as-a-proxy-server -- scroll down a bit to the XSLT part.

nginx's XSLT processor will also let you use data from other sources with the document function.