Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 824
user3311890 Avatar asked Apr 05 '17 20:04

user3311890


People also ask

How do I upload files to NGINX?

Description. nginx-upload-module - parses request body storing all files being uploaded to a directory specified by upload_store directive. The files are then being stripped from body and altered request is then passed to a location specified by upload_pass directive, thus allowing arbitrary handling of uploaded files.

How upload html file to NGINX?

html file with Nginx. To follow the procedure of serving HTML files, we will create a “www” directory using the “mkdir” command. The “mkdir” command is utilized in Linux-based systems such as CentOS for creating one or more directories. Now, press “CTRL+O” to save the content we have added in the “index.

Can NGINX serve files?

To serve static files with nginx, you should configure the path of your application's root directory and reference the HTML entry point as the index file. In this example, the root directory for the snake deployment is /home/futurestudio/apps/snake which contains all the files.

How do I upload files to my server?

The commonly way to upload data to the server is using FTP client. FTP (File Transfer Protocol) is used to transfer data from one computer (your personal computer) to another computer (webserver). FTP client looks like File Manager and you can copy (upload, download) files here from one computer to another computer.


2 Answers

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

like image 85
Clément Mondon Avatar answered Sep 28 '22 21:09

Clément Mondon


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

like image 31
Alex Popov Avatar answered Sep 28 '22 23:09

Alex Popov