后处理Nginx反向代理响应的最佳方法 [英] Best method of post processing Nginx reverse proxy response

查看:358
本文介绍了后处理Nginx反向代理响应的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一些关于在后端Grails应用程序前面从Apache切换到Nginx作为反向代理的研究.我正在尝试一些URL重写,并且遇到了从后端发回响应的问题.我可以处理位置标头的重写,但是我想知道处理链接等内容的最佳方法是什么.

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.

nginx_substitutions_filter是首选方法还是人们在响应正文中使用另一个模块进行内容替换?

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

我曾经考虑过创建Grails插件来处理基于其他请求标头的正确内容渲染,但是现在我认为最好在应用程序外部进行处理,以实现最大的灵活性和宽松的耦合.

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.

是否有任何文章介绍针对反向代理场景进行URL重写/响应后处理的最佳实践?

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

推荐答案

您可以使用Lua模块捕获响应并像Lua字符串一样操作它.大写输出的愚蠢示例:

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))

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

这篇关于后处理Nginx反向代理响应的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆