0

I need to store binary content of the request body into the file in the server's file system.

No CGI, PHP or any other executable means available, thus was looking for using nginx stuff only. I found out that when POSTing nginx saves contents of the request body into specific file pointed by $request_body_file. Is there any nginx directive to copy this file to some location within the server (where server has write permission)?

Any other suggestions are welcome.

Anonymous
  • 171
  • 12
  • The request body is only saved to a file if it is [large](http://serverfault.com/q/511789/126632). Otherwise it remains in memory. You will probably need some Lua to make that happen. – Michael Hampton Mar 11 '17 at 20:37
  • Thank you. These are bad news... I do not think I can install or include any additional modules in the current virtual installation of the nginx/apache as I am not an owner of the web hosting. I was trying to save request body through access_log directive, but it converts binaries to \0x stuff. – Anonymous Mar 11 '17 at 20:44

1 Answers1

1

You can select where the server puts the temporary file using client_body_temp_path, and client_body_in_file_only prevents nginx from deleting the file at the end of the request (and possibly forces saving to a file even if the request is small? I'm not sure, the docs aren't very clear on that). So, something like this would work:

location /upload {
    client_body_temp_path /home/my_upload_directory/;
    client_body_in_file_only on;

    client_max_body_size 2G;
}

That would create files of the form /home/my_upload_directory/000000001. I don't think there is a way to change the filename.

Matt Benzene
  • 153
  • 8