Hello!
2012/11/4 wgm.china:
> 我很想用lua-resty-upload来实现文件的上传,样例测试都通过了,不过我准备保存到文件的时间就报错。
> 后来专门测试了一下脚本:
> local file = io.open("/root/test.txt","r")
> ngx.say(file)
>
> 结果是nil。我查了一下文件也是正常的。
>
建议总是使用类似下面这样的代码来进行文件操作,这样你可以在出错时得到具体的错误信息:
local file, err = io.open("/root/test.txt","r")
if not file then
ngx.say("failed to open file: ", err)
return
end
比如下面这个比较完整的例子:
location = /t {
content_by_lua '
local f, err = io.open("/etc/shadow", "r")
if not f then
ngx.say("failed to open file: ", err)
return
end
ngx.say("file opened!")
';
}
我运行 nginx worker 进程的用户是 agentzh(一般可能就是 nobody),而这个用户是无限读取 /etc/shadow
文件的,于是访问 /t 接口会得到:
$ curl localhost:8080/t
failed to open file: /etc/shadow: Permission denied
Best regards,
-agentzh
--
邮件自: 列表“openresty”,专用于技术讨论!
发言: 请发邮件到 openresty@googlegroups.com
退订: 请发邮件至 openresty+unsubscribe@googlegroups.com
详情: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
建议: 提问的智慧 http://wiki.woodpecker.org.cn/moin/AskForHelp
教程: http://agentzh.org/misc/nginx/agentzh-nginx-tutorials-zhcn.html