'Upload files to Nginx

is there a way to upload files to a server via http using nginx?

I have a program that basically uses curl and the POST method via http to send files to a completely different enterprise software. We want to replicate something similar but are hitting a roadblock.

I have installed nginx and did a basic configuration, I want to be able to upload the files under /data/files/incoming

server {
    listen testserv1;

    location /upload/ {
      limit_except POST PUT { deny all; }
      client_body_temp_path /data/files/incoming/;
      client_body_in_file_only on;
      client_body_buffer_size 128k;
      client_max_body_size 100M;
      proxy_pass_request_headers on;
      proxy_set_body $request_body_file;
      proxy_pass http://127.0.0.1/upload;
      proxy_redirect off;
    }

I basically left the regular config on the nginx.conf and added the above. So my question is, how do I know is actually working? I did from another server try to run the program that supposedly POSTs a file but nothing. is there also a way to test this config from another system? am I missing something on the config?

Any help, anything is much appreciated.



Solution 1:[1]

You can do this without using any external module, by specifying filename into URL. I tested without the proxy, but it should be able to work :

server {
    listen testserv1;

    location ~ "/upload/([0-9a-zA-Z-.]*)$" {
        dav_methods  PUT DELETE MKCOL COPY MOVE;
        client_body_temp_path /tmp/incoming;
        alias     /data/files/incoming/$1;
        create_full_put_path   on;
        dav_access             group:rw  all:r;

        client_body_in_file_only on;
        client_body_buffer_size 128k;
        client_max_body_size 100M;
        proxy_pass_request_headers on;
        proxy_set_body $request_body_file;
        proxy_pass http://127.0.0.1/upload;
        proxy_redirect off;
    }
}

And use : curl -T test.zip http://testserv1/upload/text.zip

Solution 2:[2]

Have a look at the nginx_upload_module: https://www.nginx.com/resources/wiki/modules/upload/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Alex Popov