新手问题 nginx 权限问题

xiaoxiao · 2013年07月18日 · 最后由 leopku 回复于 2013年07月18日 · 5113 次阅读

我的项目用 nginx 部署,其中有个控制器 upload 是上传文件的具体代码如下:

def uploadFile
   upload=params[:upload]
   name = upload['datafile'].original_filename
    directory = 'public/data'
    # create the file path
    path = File.join(directory,name)
    # write the file
    File.open(path, "wb") { |f| f.write(upload['datafile'].read)}
   end
end

但是 nginx 老是提示

Errno::EACCES in BoyController#uploadfile

Permission denied - public/data/运动检测项.xls 我的 nginx 配置文件如下

user  root;
worker_processes  1;

..... 我已经将 user 设置为 root 了,为什么在 linux 下还是提示权限不够

1 楼 已删除

应该是应用服务器的权限不够。你应用是以什么用户启动的了? public/data/目录允许此用户写不?

我设置的 nginx 用户是 root,权利应该是最高的,不知道为什么不行

#3 楼 @xiaoxiao 你的 rails 是以什么应用服务器启动的?Phusion Passenger 还是其它的?它们是以什么用户启动的?

phusion passenger.问题已解决,虽然我将配置文件中设置 user root 但是我查看进程发现还是有的 nginx 模块的进程是默认的 nobody,故无法创建目录。只能将 public 的权限改成 777 才行

为了安全方面的因素,nginx 用户不要使用 root 将 nginx 用户改成 nginx 或 www-data 等普通用户,然后将 public 目录(建议整个项目)的所有者改为 nginx 相同用户

改为 777 看似解决了问题,实际上却留下安全隐患

需要 登录 后方可回复, 如果你还没有账号请 注册新账号