0
我想用nginx來獲取post請求內容,數據enctype是multipart/form-data。我用下面的配置,nginx的配置:如何用nginx獲取post請求內容,數據enctype是multipart/form-data
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。
THX非常感謝!
thx非常多,「access_by_lua」是工作。我想記錄附件數據流,用戶上傳到Web應用程序並使用apached commons-fileupload組件。 –