Jsp 如何使用nginx获取post请求内容&xFF0C;数据类型为多部分/表单数据

Jsp 如何使用nginx获取post请求内容&xFF0C;数据类型为多部分/表单数据,jsp,nginx,lua,Jsp,Nginx,Lua,我想使用nginx获取post请求内容,数据类型是multipart/formdata。我使用了以下配置nginx config: upstream syy{ server 201.23.xx.xx; } server { listen 443; server_name localhost; lua_need_request_body on; location /test { root html;

我想使用nginx获取post请求内容,数据类型是multipart/formdata。我使用了以下配置nginx config:

 upstream syy{
     server 201.23.xx.xx;
    }


server {
    listen       443;
    server_name  localhost;



lua_need_request_body on;

    location /test {
        root   html;
        index  index.html index.htm;
        proxy_pass http://syy;
    proxy_buffering off;
    lua_code_cache off;
    content_by_lua_file /usr/local/openresty/luasrc/att.lua;
    }
lua文件:

function writefile(filename,info)
local file = assert(io.open(filename,"ab"))
file:write(info)
file:close()
end

ngx.req.read_body()
local value = "/home/tmp/"..os.date("%Y%m%d%H")..".att"
local data = ngx.req.get_post_args()
if data ~= nil then
    if type(data) == "table" then
        writefile(value,table.concat(data,",").."\n")
    else
        writefile(value,data.."\n")
    end
end
但是当我访问测试网站时,我只得到一个空文件,比如login.jsp,它是一个空文件。浏览器提示我下载login.jsp

非常感谢!

首先,“代理通行证”和“内容文件”不应该一起使用。您可以使用proxy\u pass或content\u by\u lua。这就是浏览器试图下载文件而不是实际执行文件的原因

不太清楚您想要实现什么,但您可能希望使用“按文件重写”,而不是“按文件重写内容”。在这个阶段,您可以在反向代理请求之前进行一些操作。您也可以对所使用的代码段使用“access\u by\u lua*”,但这完全取决于您想要使用的nginx功能

rewrite_by_lua_file /usr/local/openresty/luasrc/att.lua;
首先,“代理传递”和“内容通过文件”不应该一起使用。您可以使用proxy\u pass或content\u by\u lua。这就是浏览器试图下载文件而不是实际执行文件的原因

不太清楚您想要实现什么,但您可能希望使用“按文件重写”,而不是“按文件重写内容”。在这个阶段,您可以在反向代理请求之前进行一些操作。您也可以对所使用的代码段使用“access\u by\u lua*”,但这完全取决于您想要使用的nginx功能

rewrite_by_lua_file /usr/local/openresty/luasrc/att.lua;
非常感谢,“访问”是工作。我想记录用户上传到web应用程序并使用apached commons fileupload component.thx的附件数据流,“access_by_lua”非常有用。我想记录用户上传到web应用程序并使用apached commons fileupload组件的附件数据流。