Hello!
2012/9/20 azure wang:
> 现在的代码在nginx_lua 0.6.6rc1上基本可以工作了:
>
多谢你的反馈!
你下面给出的这个以严格非缓冲方式转发大 POST 请求给后端的案例值得分享给 openresty
中文邮件列表:https://groups.google.com/group/openresty
这样更多的用户(包括搜索引擎用户)可以看到 :)
Thanks!
-agentzh
> local req_sock, err = ngx.req.socket()
> if not req_sock then
> ngx.log(ngx.ERR,err)
> ngx.exit(500)
> end
> local method = ngx.req.get_method()
> local sock = ngx.socket.tcp()
> sock:settimeout(1000)
> local ok, err = sock:connect("127.0.0.1", 7000)
> if not ok then
> ngx.log(ngx.ngx.ERR, err)
> ngx.exit(500)
> end
> -- headers
> local req = {}
> local headers = ngx.req.get_headers()
> headers["Expect"] = nil
> req[#req+1] = string.format("%s %s %s\r\n", method, ngx.var.uri, "HTTP/1.0")
> for k, v in pairs(headers) do
> req[#req+1] = string.format("%s: %s\r\n", k, v)
> end
> req[#req+1] = "\r\n"
> local bytes, err = sock:send(table.concat(req))
> if not bytes then
> ngx.log(ngx.ngx.ERR, "send headers error")
> ngx.exit(500)
> end
> -- body
> while true do
> local chunk, _, part = req_sock:receive(1024 * 64)
> if not part then
> sock:send(chunk)
> else
> sock:send(part)
> break
> end
> end
> local line = sock:receive("*l")
> sock:close()
> local code_pos = string.find(line, " ")
> if code_pos then
> local code = tonumber(string.sub(line, code_pos+1, code_pos+3))
> if code and code >= 100 then
> ngx.exit(code)
> else
> exit(500)
> end
> else
> ngx.exit(500)
> end
>
>
> 在 2012年9月20日 下午3:23,azure wang 写道:
>
>> 发现主要我在ngx.exit(20x) 前面输出内容,CURL看到的返回code都编程200了 如果没有ngx.print或者ngx.say输出内容
>> ngx.exit返回的是我设置的code
>>
>>
>> curl -iT test.dat http://127.0.0.1:8080/fff/ddd.dat
>> HTTP/1.1 100 Continue
>>
>> HTTP/1.1 200 OK
>> Server: nginx/1.2.2
>> Date: Thu, 20 Sep 2012 19:16:01 GMT
>> Content-Type: application/octet-stream
>> Transfer-Encoding: chunked
>> Connection: keep-alive
>>
>> Uploaded
>>
>> 在 2012年9月20日 下午3:20,azure wang <azu...@gmail.com>写道:
>>
>>> nginx_lua 0.6.6rc1 目前测试正常,并
>>>
>>> 且在0.5.12版本中发现的ngx.exit(201) ,ngx.exit(20x)等 curl看到全是200 的问题也消失了
>>>
>>> 这样我就可以用nginx_lua 为我的基于HTTP PUT方式上传文件服务做代理了,而且是流的方式
>>> 上传的文件不会先被nginx缓存到本地了。对大文件更加友好。
>>>
>>>
>>> 在 2012年9月20日 下午2:59,azure wang <azu...@gmail.com>写道:
>>>
>>>> 我使用的版本是v0.5.11 nginx版本是1.2.2
>>>>
>>>> 我去现在最新的nginx_lua试试
>>>>
>>>>
>>>> 在 2012年9月20日 上午5:43,agentzh 写道:
>>>>
>>>>> Hello!
>>>>>
>>>>> On Wed, Sep 19, 2012 at 3:02 AM, azure wang <azu...@gmail.com> wrote:
>>>>> >
>>>>> > 我用nginx做反向代理 但是我的请求时PUT一个大文件,测试发现nginx会先把文件缓存到本地然后等接受完毕统一发送。
>>>>> >
>>>>>
>>>>> 多谢你提供的报告!但是我希望你能在 bug 报告中提供一下更多的信息,比如你使用的 nginx 和 ngx_lua
>>>>> 模块的版本号,以及你所在的操作系统的信息。多谢!
>>>>>
>>>>> 值得一提的是,cosocket send 部分最近经过了重写。你能否尝试一下最新的 ngx_lua 0.6.6rc1?
>>>>>
>>>>> https://github.com/chaoslawful/lua-nginx-module/tags
>>>>>
>>>>> Best regards,
>>>>> -agentzh