Hello!
2013/6/7 claresuns:
> 尝试的方法有
> 1:通过ngx.location.capture发起子请求,子请求中调用upstream。遇到的问题是,路径不知道怎么传到子请求中,比如访问http://www.aaa.com/advice/index.html?a=1&b=1,这段/advice/index.html?a=1&b=1怎么传给子请求发起upstream。;
>
可以通过子请求的 URL 参数把整个 URL 传递过去,即在父请求的 Lua 代码里面这么写:
ngx.location.capture("/http-sub", { args = "/advice/index.html?a=1&b=1" })
然后把子请求的 location 定义成这个样子:
location = /http-sub {
internal;
proxy_pass http://mybackend$args;
}
> 2:通过body_filter,由于chunked原因,多次执行过滤方法,没法做到一次替换。
>
你或许需要使用像 ngx_replace_filter 这样的模块来进行流式正则替换?
https://github.com/agentzh/replace-filter-nginx-module
> 3:通过ngx.socket.tcp的连接,模拟发送,获取再返回。遇到的问题是receive,不太清楚如何能获取完整的header与body内容,尝试过while一直去receive。 或者获取Content-Length然后加入参数输出。
>
这里可以参考第三方的 lua-resty-http 库的实现:
https://github.com/liseen/lua-resty-http
Best regards,
-agentzh