Best method of post processing Nginx reverse proxy response

让人想犯罪 __ 提交于 2019-12-22 04:29:18

问题


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?


回答1:


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




回答2:


If you want to replace only the headers, HeadersMore 3rd party module is great for that. Other than that, susbstiution module seems to be the only option.

But I would suggest you make the backend return the correct page. Modifying every response uses resources and takes time.



来源:https://stackoverflow.com/questions/695630/best-method-of-post-processing-nginx-reverse-proxy-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!