Linux - client_body_in_file_only - 如何设置临时文件的文件权限?

问题描述 投票:5回答:2

我们在nginx中使用client_body_in_file_only选项,以允许通过Ajax上传文件。配置如下所示:

location ~ ^(\/path1|\path2)$ {

  limit_except POST { deny all; }
  client_body_temp_path      /path/to/app/tmp;
  client_body_in_file_only   on;
  client_body_buffer_size    128K;
  client_max_body_size       1000M;

  #this option is a quick hack to make sure files get saved on (ie this type of request goes to) on a specific server
  proxy_pass                 http://admin;
  proxy_pass_request_headers on;
  proxy_set_header           X-FILE $request_body_file;
  proxy_set_body             off;
  proxy_redirect             off;

  # might not need?
  proxy_read_timeout         3m;
}

这是有效的,但处理请求的Web服务器进程(Mongrel)必须sudo headers['X-FILE']中的临时文件,然后才能对它执行任何操作。这是因为临时文件具有600权限。

我对这种方法不满意,这需要我们编辑/etc/sudoers文件,以允许Web服务器用户在没有密码的情况下执行sudo chmod。感觉非常不安全。

有没有办法,使用nginx配置,更改创建的临时文件的权限,例如775?

编辑:我只是尝试在nginx init配置中更改umask选项的值,然后重新启动nginx,但它没有帮助。它曾在0022,我改为0002。在这两种情况下,它都拥有600个权限。

EDIT2:我也试过在qginxswpoi行下在nginx配置中添加这一行。

proxy_redirect

但是,它没有任何区别 - 它仍然只有proxy_store_access user:rw group:rw all:r;

file nginx temp
2个回答
4
投票

通过user:rw源查看,似乎唯一可以修改临时文件权限的机制是请求的nginx属性,在request_body_file_group_access中查询:

ngx_http_write_request_body()

但即使这样也限制了你对if (r->request_body_file_group_access) { tf->access = 0660; } 的看法,它似乎不是用户可设置的属性,只有被0660模块使用。

权限最终在ngx_http_dav中设置,默认为ngx_open_tempfile()

0600

所以似乎目前没有基于配置的解决方案。如果你愿意/能够从源代码构建fd = open((const char *) name, O_CREAT|O_EXCL|O_RDWR, access ? access : 0600); ,一种可能性是应用一个简单的补丁来设置你在nginx中想要的权限:

ngx_http_write_request_body()

我测试了这个并获得了以下内容,第一个文件没有修改就上传了,第二个文件带有它:

+    tf->access = 0644;
+
     if (r->request_body_file_group_access) {
         tf->access = 0660;
     }

     rb->temp_file = tf;

3
投票

看来,目前无法配置文件权限,但有一个$ ls -al /tmp/upload/ total 984 drwxr-xr-x 2 nobody root 12288 Feb 18 13:42 . drwxrwxrwt 16 root root 12288 Feb 18 14:24 .. -rw------- 1 nobody nogroup 490667 Feb 18 13:40 0000000001 -rw-r--r-- 1 nobody nogroup 490667 Feb 18 13:42 0063184684

文件权限始终为0600,使应用程序根本无法读取文件。 [...]这是目前不支持的情况:[Nginx]使用默认权限[...] 0600创建临时文件(除非设置了official feature request - 但遗憾的是该属性不可设置)。

该门票于2018年10月开放,优先次序较低。

© www.soinside.com 2019 - 2024. All rights reserved.