So, you want
nginx to proxy a request from the client to the backend server, and then, prior to returning the reply of the backend to the client, pipe such reply through another external processor?
I don't think you can do the above with any official
nginx modules as provided by Igor Sysoev and Nginx, Inc currently. The closest thing that's available for altering the body of the response is a few filter modules that come together with nginx, but are turned off by default, including the
gzip on; is what you actually want instead?
Or, potentially, if you know
perl and are willing to run an entirely experimental module, take a look at embedding
nginx, with an official nginx module that is turned off by default and is (somewhat obviously) totally experimental:
Another option is to use some kind of a Fast-CGI setup to which you'll be redirecting the requests, where, in turn, your Fast-CGI script will be doing requests to the backend, and then the final processing, prior to returning the replies back to nginx to cache and return to the user.
There is also
proxy_set_body (but no
fastcgi_set_body yet), to change the body of the request (e.g. from what the client has supplied), but there does not seem to be any equivalent directive or variable to get the body of the response, in order to pass to a somehow subsequent request to a post-processor. In any case, a filter module is probably what you want for a post-processor.
(Also, you do realise that a naive approach of
forking and piping replies through a regular executive is going to be extra-extra slow, right?)
To summarise, I think
gzip on; is exactly what you're looking for; else, provided you can modify the original webapp, I think your very best bet might be to install some kind of post-processor within the webapp itself, which would seem like the next easiest solution overall. Potentially, you could look into how the filter modules are implemented, e.g. the aforementioned ngx_http_addition_filter_module.c, plus some more obviously-relevant filters like ngx_http_gzip_filter_module.c, and implement your own embedded filter module. Or hire Nginx, Inc. to write this for you! But, seriously,
gzip on; just works, and is likely to give you much better results without any hassles, performance or stability issues, and it's already compiled in by default, you just have to enable it in