Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best method of post processing Nginx reverse proxy response

I'm doing some researching on switching from Apache to Nginx as a reverse proxy in front of a Grails application on the backend. I'm playing around with some URL rewriting and have run into an issue with the response being sent back from my back end. I can handle the location header rewrite but I'm wondering what the best way to process the actually content is for link and such.

Is nginx_substitutions_filter the preferred method or is there another module that folks use to do content replacement in the response body?

I've thought about creating a Grails plugin to handle rendering the correct content based on additional request headers but now I'm thinking that would be best handled outside the application to allow for the most flexibility and loose coupling.

Are there any articles about best practices for doing URL rewriting/response post processing for reverse proxy scenarios?

like image 571
ahanson Avatar asked Mar 29 '09 23:03

ahanson


1 Answers

You can use the Lua module to capture the response and manipulate it like a Lua string. Silly example to upper case the output:

res = ngx.location.capture('/some/path')
ngx.print(string.upper(res.body))

see http://wiki.nginx.org/HttpLuaModule#ngx.location.capture

like image 136
bakins Avatar answered Sep 28 '22 05:09

bakins