gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:00:50 31 4
gpt4 key购买 nike

我们在 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?

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

EDIT2:我也尝试在 proxy_redirect 下添加这一行行,在 nginx 配置中。
proxy_store_access user:rw group:rw all:r;

但是,它没有任何区别 - 它仍然只有 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;

我对此进行了测试并获得了以下内容,第一个文件未经修改就上传了,第二个文件也有:
$ 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

关于file - Linux - client_body_in_file_only - 如何为临时文件设置文件权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54708301/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com