8

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?

4

2 回答 2

2

您可以使用 Lua 模块来捕获响应并像 Lua 字符串一样对其进行操作。将输出大写的愚蠢示例:

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

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

于 2013-01-31T02:13:14.217 回答
0

如果您只想替换标题,HeadersMore 3rd 方模块非常适合。除此之外,susbstiution 模块似乎是唯一的选择。

但我建议你让后端返回正确的页面。修改每个响应都会占用资源并且需要时间。

于 2012-03-31T09:10:03.480 回答