Nginx上傳PUT和POST

Nginx上傳PUT和POST

我試圖讓 nginx 接受 POST 和 PUT 方法來上傳檔案。我已經編譯了nginx_upload_module-2.2.0。

我找不到任何方法。我只是想只使用 nginx,沒有反向代理,沒有其他後端,也沒有 php。

這是可以實現的嗎?

這是我的會議:

nginx version: nginx/1.2.3TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-cc-opt='-O2 -g' --add-module=/usr/src/nginx-1.2.3/nginx_upload_module-2.2.0


server {
    listen       80;
    server_name  example.com;

    location / {
        root   /html;
        autoindex on;
    }

    location /upload {
        root    /html;
        autoindex on;
        upload_store /html/upload 1;

        upload_set_form_field $upload_field_name.name "$upload_file_name";
        upload_set_form_field $upload_field_name.content_type "$upload_content_type";
        upload_set_form_field $upload_field_name.path "$upload_tmp_path";

        upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5";
        upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";
        upload_pass_form_field "^submit$|^description$";
        upload_cleanup 400 404 499 500-505;
    }
}

作為上傳表單,我嘗試使用本頁末尾列出的表單:http://grid.net.ru/nginx/upload.en.html

答案1

關於 POST 請求:也許您沒有在上傳目標目錄中建立目錄 0 1 2 3 4 5 6 7 8 9 ?

您始終可以將 DAV 用於 PUT 請求,您已經將其編譯到您的 nginx 中:

location /upload {
  alias     upload/data;
  client_body_temp_path  upload/client_tmp;

  dav_methods  PUT DELETE MKCOL COPY MOVE;

  create_full_put_path   on;
  dav_access             group:rw  all:r;

}

你需要這個(在 http 或 location 中):

client_max_body_size 10000m;

現在試試看:

curl -T ubuntu-10.04.4-alternate-amd64.iso http://localhost/upload/blah2

乾杯!格奧爾格

答案2

第三方上傳模組根本不支援PUT。如果您想使用 PUT 上傳,則必須使用標準 nginx 上傳處理來執行此操作。

相關內容