Nginx上传PUT和POST

w00*_*00t 5 nginx upload

我试图让 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;
    }
}
Run Code Online (Sandbox Code Playgroud)

作为上传表单,我尝试使用本页末尾列出的表单:http : //grid.net.ru/nginx/upload.en.html

Geo*_*org 6

关于 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;

}
Run Code Online (Sandbox Code Playgroud)

你需要这个(在 http 或位置):

client_max_body_size 10000m;
Run Code Online (Sandbox Code Playgroud)

现在试试:

curl -T ubuntu-10.04.4-alternate-amd64.iso http://localhost/upload/blah2
Run Code Online (Sandbox Code Playgroud)

干杯! 乔治


Mar*_*ald 1

第三方上传模块根本不支持PUT。如果您想使用 PUT 上传,则必须使用标准 nginx 上传处理来执行此操作。