zhuan : http://www.grid.net.ru/nginx/upload.en.html
Nginx upload module (v 2.2.0) |
rus eng |
A module for nginx web server for handling file uploads using multipart/form-data encoding (RFC 1867) and resumable uploads according to this protocol.
Description
The 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. Each of file fields are being replaced by a set of fields specified by upload_set_form_field directive. The content of each uploaded file then could be read from a file specified by $upload_tmp_path variable or the file could be simply moved to ultimate destination. Removal of output files is controlled by directive upload_cleanup. If a request has a method other than POST, the module returns error 405 (Method not allowed). Requests with such methods could be processed in alternative location via error_pagedirective.
Configuration directives
syntax: upload_pass <location>
default: none
severity: mandatory
context: server, location
Specifies location to pass request body to. File fields will be stripped and replaced by fields, containig necessary information to handle uploaded files.
syntax: upload_resumable <on/off>
defaultoff
severity: mandatory
context: main, server, location
Enables resumable uploads.
syntax: upload_store <directory> [<level 1> [<level 2> ] ... ]
default: none
severity: mandatory
context: server, location
Specifies a directory to which output files will be saved to. The directory could be hashed. In this case all subdirectories should exist before starting nginx.
syntax: upload_state_store <directory> [<level 1> [<level 2> ] ... ]
default: none
severity: optional
context: server, location
Specifies a directory that will contain state files for resumable uploads. The directory could be hashed. In this case all subdirectories should exist before starting nginx.
syntax: upload_store_access <mode>
default: user:rw
severity: optional
context: server, location
Specifies access mode which will be used to create output files.
syntax: upload_set_form_field <name> <value>
default: none
severity: optional
context: server, location
Specifies a form field(s) to generate for each uploaded file in request body passed to backend. Both name and value could contain following special variables:
- $upload_field_name -- the name of original file field
- $upload_content_type -- the content type of file uploaded
- $upload_file_name -- the original name of the file being uploaded with leading path elements in DOS and UNIX notation stripped. I.e. "D:\Documents And Settings\My Dcouments\My Pictures\Picture.jpg" will be converted to "Picture.jpg" and "/etc/passwd" will be converted to "passwd".
- $upload_tmp_path -- the path where the content of original file is being stored to. The output file name consists 10 digits and generated with the same algorithm as in proxy_temp_path directive.
These variables are valid only during processing of one part of original request body.
example:
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";
syntax: upload_aggregate_form_field <name> <value>
default: none
severity: optional
context: server, location
Specifies a form field(s) containing aggregate attributes to generate for each uploaded file in request body passed to backend. Both name and value could contain standard nginx variables, variables from upload_set_form_field directive and following additional special variables:
- $upload_file_md5 -- MD5 checksum of the file
- $upload_file_md5_uc -- MD5 checksum of the file in uppercase letters
- $upload_file_sha1 -- SHA1 checksum of the file
- $upload_file_sha1_uc -- SHA1 checksum of the file in uppercase letters
- $upload_file_crc32 -- hexdecimal value of CRC32 of the file
- $upload_file_size -- size of the file in bytes
- $upload_file_number -- ordinal number of file in request body
The value of a field specified by this directive is evaluated after successful upload of the file, thus these variables are valid only at the end of processing of one part of original request body.
WARNING: variables $upload_file_md5, $upload_file_md5_uc, $upload_file_sha1 and $upload_file_sha1_uc utilize additional resourses to calculate MD5 and SHA1 checksums.
example:
upload_aggregate_form_field $upload_field_name.md5 "$upload_file_md5"; upload_aggregate_form_field $upload_field_name.size "$upload_file_size";
syntax: upload_pass_form_field <regex>
default: none
severity: optional
context: server, location
Specifies a regex pattern for names of fields which will be passed to backend from original request body. This directive could be specified multiple times per location. Field will be passed to backend as soon as first pattern matches. For PCRE-unaware enviroments this directive specifies exact name of a field to pass to backend. If directive is omitted, no fields will be passed to backend from client.
example:
upload_pass_form_field "^submit$|^description$";
For PCRE-unaware environments:
upload_pass_form_field "submit"; upload_pass_form_field "description";
syntax: upload_cleanup <HTTP status/range> [<HTTP status/range>...]
default: none
severity: optional
context: server, location
Specifies HTTP statuses after generation of which all file successfuly uploaded in current request will be removed. Used for cleanup after backend or server failure. Backend may also explicitly signal errornous status if it doesn't need uploaded files for some reason. HTTP status must be a numerical value in range 400-599, no leading zeroes are allowed. Ranges of statuses could be specified with a dash.
example:
upload_cleanup 400 404 499 500-505;
syntax: upload_buffer_size <size>
default: size of memory page in bytes
severity: optional
context: server, location
Size in bytes of write buffer which will be used to accumulate file data and write it to disk. This directive is intended to be used to compromise memory usage vs. syscall rate.
syntax: upload_max_part_header_len <size>
default: 512
severity: optional
context: server, location
Specifies maximal length of part header in bytes. Determines the size of the buffer which will be used to accumulate part headers.
syntax: upload_max_file_size <size>
default: off
severity: optional
context: main, server, location
Specifies maximal size of the file. Files longer than the value of this directive will be omitted. This directive specifies "soft" limit, in the sense, that after encountering file longer than specified limit, nginx will continue to process request body, trying to receive remaining files. For "hard" limit client_max_body_sizedirective must be used. The value of zero for this directive specifies that no restrictions on file size should be applied.
syntax: upload_limit_rate <rate>
default: 0
severity: optional
context: main, server, location
Specifies upload rate limit in bytes per second. Zero means rate is unlimited.
syntax: upload_max_output_body_len <size>
default: 100k
severity: optional
context: main, server, location
Specifies maximal length of the output body. This prevents piling up of non-file form fields in memory. Whenever output body overcomes specified limit error 413 (Request entity too large) will be generated. The value of zero for this directive specifies that no restrictions on output body length should be applied.
syntax: upload_tame_arrays <on/off>
default: off
severity: optional
context: main, server, location
Specifies whether square brackets in file field names must be dropped (required for PHP arrays).
syntax: upload_pass_args<on/off>
default: off
severity: optional
context: main, server, location
Enables forwarding of query arguments to location, specified by upload_pass. Ineffective with named locations. Example:
<form action="/upload?id=5"> ... location /upload { upload_pass /internal_upload; upload_pass_args on; } ... location /internal_upload { ... proxy_pass http://backend; }
In this example backend gets request URI "/upload?id=5". In case of upload_pass_args off backend gets "/upload".
Example configuration
server { client_max_body_size 100m; listen 80; # Upload form should be submitted to this location location /upload { # Pass altered request body to this location upload_pass @test; # Store files to this directory # The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist upload_store /tmp 1; # Allow uploaded files to be read only by user upload_store_access user:r; # Set specified fields in request body 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"; # Inform backend about hash and size of a file 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; } # Pass altered request body to a backend location @test { proxy_pass http://localhost:8080; } }
Example form
<html> <head> <title>Test upload</title> </head> <body> <h2>Select files to upload</h2> <form name="upload" method="POST" enctype="multipart/form-data" action="/upload"> <input type="file" name="file1"><br> <input type="file" name="file2"><br> <input type="file" name="file3"><br> <input type="file" name="file4"><br> <input type="file" name="file5"><br> <input type="file" name="file6"><br> <input type="submit" name="submit" value="Upload"> <input type="hidden" name="test" value="value"> </form> </body> </html>
Download
Latest version 2.2.0: tar.gz zip
Version 2.0.12: tar.gz zip
Version 2.0.11: tar.gz zip
Version 2.0.10: tar.gz zip
Version 2.0.9: tar.gz zip
Version 2.0.8: tar.gz zip MD5 SHA1
Version 2.0.7: tar.gz zip MD5 SHA1
Version 2.0.6: tar.gz zip MD5 SHA1
Version 2.0.5: tar.gz zip MD5 SHA1
Version 2.0.4: tar.gz zip MD5 SHA1
Version 2.0.3: tar.gz zip MD5 SHA1
Version 2.0.2: tar.gz zip MD5 SHA1
or go to download area
Browse repository
http://github.com/vkholodkov/nginx-upload-module/tree/2.2
Browse documentation for earlier versions
Version 2.0.12
Version 2.0.11
Version 2.0.10
Version 2.0.9
Version 2.0.8
Version 2.0.7
Version 2.0.6
Version 2.0.5
Version 2.0.4
Version 2.0.3
Version 2.0.2
How to use
Download sources from one of the links above. Unpack the archive:
tar xvzf nginx_upload_module-2.2.0.tar.gz
Configure nginx with additional module:
For nginx versions other than 0.7.44-51:
cd <path to nginx sources> ./configure --add-module=<path to upload module sources> make make install
cd <path to nginx sources> CFLAGS="-Dnginx_version=7052" ./configure --add-module=<path to upload module sources> make make install
Nginx
nginx -- is a web-server, developed by Igor Sysoev.
Licence
The above-described module is an addition to nginx web-server, nevertheless they are independent products. The licence of above-described module is BSD You should have received a copy of license along with the source code. By using the materials from this site you automatically agree to the terms and conditions of this license. If you don't agree to the terms and conditions of this license, you must immediately remove from your computer all materials downloaded from this site.
Contact author
Valery Kholodkov valery+nginx@grid.net.ru
Please use address extension while composing an Email to me.
Copyright (C) 2006, 2008-2010 Valery Kholodkov
Module copyright notices see in module sources.
国内同类文章可见:
http://wenku.baidu.com/view/3e1eebf44693daef5ef73dbe.html
相关推荐
**Nginx Upload Module 2.2.0 模块详解** `nginx_upload_module-2.2.0.tar.gz` 是一个针对 Nginx Web 服务器的第三方模块,主要用于处理文件上传功能。Nginx 作为一款高性能的 HTTP 和反向代理服务器,原生并不直接...
这可能是因为`nginx-upload-module`是为某个较旧的Nginx版本设计的,因此它的源代码可能没有包含针对新版本Nginx所做的更新。解决这种问题通常需要找到适配新版本Nginx的模块版本,或者对源代码进行必要的修改以适应...
【Nginx Upload Module 深度解析】 Nginx Upload Module 是一款为 Nginx Web 服务器设计的扩展模块,主要用于处理文件上传功能。它提供了高效、灵活且可靠的文件上传解决方案,支持大文件分块上传以及断点续传,是...
**Nginx Upload Module 2.3.0 安装详解** Nginx Upload Module 是一个用于 Nginx 的第三方模块,它允许用户在通过 HTTP 协议上传大文件时进行处理,例如分块上传、限速、断点续传等。这个模块对于构建支持大文件...
《FastDFS-Nginx-Module V1.19:构建高效稳定的文件服务器系统》 FastDFS-Nginx-Module V1.19 是一个专为Nginx设计的FastDFS扩展模块,它允许Nginx直接与FastDFS进行交互,从而实现高效的文件上传和下载服务。...
标题中的"fastdfs-nginx-module_v1.16.tar.gz"是一个开源项目,它是一个用于Nginx服务器的模块,旨在使Nginx能够与FastDFS文件存储系统无缝集成。FastDFS是一个轻量级的开源分布式文件系统,适用于互联网和企业内部...
包含upload-module的nginx-1.21.6,针对windows平台64位的编译的二进制(exe)文件。 为了upload-module能在window平台编译通过,进行部分代码修改,修改内容详见https://github.com/chnykn/bimface
《深入解析fastdfs-nginx-module_v1.16.tar.gz:构建高效文件服务器的利器》 在现代互联网应用中,文件存储与传输是不可或缺的一部分。FastDFS作为一个轻量级、高性能的分布式文件系统,因其简单易用、稳定可靠的...
**Nginx Upload Module 2.2 知识点详解** Nginx作为一个高性能的HTTP和反向代理服务器,广泛应用于各类网站和Web服务中。然而,原生的Nginx并不支持大文件的上传功能,为了实现这个需求,开发者们开发了Nginx ...
**Nginx Upload Progress 模块详解** Nginx 是一款高性能、轻量级的 Web 服务器/反向代理服务器,被广泛应用于互联网服务。它以其稳定性和高并发能力受到赞誉。在处理大文件上传时,为了提供更好的用户体验,开发者...
Lua-Nginx-Module,简称lua-nginx-module,是Nginx服务器的一个重要扩展模块,它将强大的Lua脚本语言集成到Nginx中,允许用户在Nginx配置文件中直接编写Lua代码,极大地增强了Nginx的功能性和灵活性。版本0.10.13是...
nginx-upload-module模块源码,用于nginx配置文件上传功能
Nginx-Module-VTS是Nginx的一个增强模块,主要功能是提供详细的Web服务器访问统计和性能监控。Prometheus是一款流行的开源监控和警报工具,广泛用于收集和分析各种系统的指标。在本场景中,Nginx-Module-VTS与...
本文将详细解析如何将FastDFS的Nginx模块(fastdfs-nginx-module-1.20.zip)安装并配置到Nginx中,实现高效、稳定的服务。 首先,确保你已经安装了FastDFS和Nginx的基础环境。FastDFS提供了数据存储和文件管理的...
《FastDFS-Nginx-Module V1.20详解及应用实践》 FastDFS-Nginx-Module是针对FastDFS分布式文件系统的一款扩展模块,它主要用于整合Nginx web服务器,实现通过Nginx直接访问FastDFS存储的文件,极大地提高了文件服务...
《FastDFS-Nginx-Module 1.24:高效文件服务器集成详解》 FastDFS-nginx-module 1.24 是一个针对 FastDFS 文件系统的 Nginx 模块,它使得 Nginx 可以无缝地与 FastDFS 集成,提供了高效的文件上传、下载服务。这一...
《FastDFS-Nginx-Module 1.22:构建高效Web服务器的融合解决方案》 在互联网服务领域,Nginx以其高效的性能和强大的反向代理能力被广泛应用于Web服务器,而FastDFS作为轻量级的分布式文件系统,能够有效地解决...
在这个场景下,`fastdfs-nginx-module.zip`扮演着关键的角色,它是FastDFS与Nginx之间的重要桥梁。 FastDFS通常与Nginx结合使用,Nginx作为一个强大的反向代理和负载均衡服务器,负责接收HTTP请求,然后将这些请求...
`nginx_upload_module`是一个用于Nginx服务器的第三方模块,它允许处理和存储上传的文件。结合Lua脚本,我们可以实现更灵活和强大的上传功能。这篇博文(链接:)可能详细介绍了如何在Nginx中集成`nginx_upload_...