We use the client_body_in_file_only option with nginx, to allow file upload via Ajax. The config looks like this:
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;
}
This works, but the web server process (Mongrel) that handles the request has to sudo
the temp file that comes through in headers['X-FILE']
, before it can do anything with it. This is because the temp file comes through with 600
permissions.
I'm not happy with this approach, which requires us to edit the /etc/sudoers
file to allow the web server user to do sudo chmod
without a password. It feels very unsecure.
Is there a way, with the nginx config, to change the permissions on the temp file that is created, eg to 775?
EDIT: I just tried changing the value of the umask
option in the nginx init config, then restarting nginx, but it didn't help. It had been at 0022
, I changed it to 0002
. In both cases it comes through with 600 permissions.
EDIT2: I also tried adding this line under the proxy_redirect
line, in the nginx config.
proxy_store_access user:rw group:rw all:r;
But, it didn't make any difference - it still just has user:rw