Nginx Upload Module Upload

Source: Internet
Author: User
Tags sha1

"Turn" 75084282

I. Nginx Upload module principle

Official Document: Http://www.grid.net.ru/nginx/upload.en.html

Nginx upload module accepts user uploaded files through nginx service, and automatically resolves all files stored in the request body to the Upload_store specified directory. These file information is detached from the original request body and reassembled according to the configuration in the nginx.conf to be processed by the segment specified by Upload_pass, allowing the processing of any uploaded file. The value of the file field in each upload file is replaced by a series of upload_set_form_field instruction values. The contents of each uploaded file can be read from the $upload_tmp_path variable, or the file can be transferred to the destination directory. The uploaded file removal can be controlled via the Upload_cleanup command. If the requested method is not post, the module returns a 405 error (405 not allowed), which can be handled by the Error_page directive.

The specific process is as follows:

    1. User access to a page that can choose to upload files

    2. User Submit Form

    3. The browser sends the file and information about the file to the server as part of the request

    4. The server saves the file to the temporary storage directory Upload_store

    5. Upload_pass The specified PHP page that handles the form submission copies the file from the Upload_store to the persistent storage location

Two. Nginx Upload module configuration parameters

UPLOAD_PASS Specifies the PHP address for subsequent processing. The fields in the file will be separated and replaced with the necessary information processing to upload the file.

Upload_resumable whether to initiate a recoverable upload.

Upload_store Specifies the upload file storage address (directory). Directories can be hashed, in which case all subdirectories must exist before Nginx is started.

Upload_state_store specifies that the upload file status information directory can be restored by saving the uploaded files. Directories can be hashed, in which case all subdirectories must exist before Nginx is started.

Upload_store_access access to uploaded files, user:r refers to user-readable

Upload_pass_form_field a parameter that goes from the form to the back end, and can be represented by a regular expression. :

$upload _field_name– The name of the field in the original file

Upload_pass_form_field "^submit| DEscription |description ";

This means that the Submit,description two fields are also passed through Upload_pass to the back-end PHP processing. If you want to pass all the form fields to the back end can be used Upload_pass_form_field "^.*$";

The Upload_set_form_field name and value may contain the following special variables:

$upload the name value of the _field_name form

$upload _content_type Types of uploaded files

$upload The original file name uploaded by the _file_name client

$upload _tmp_path file is saved on the server after uploading

Upload_aggregate_form_field can be used more than a few variables, the file is received after the generated and passed to the backend

The MD5 checksum value of the $upload _file_md5 file

The MD5 checksum value $upload _FILE_MD5_UC capital letters

The SHA1 checksum value of the $upload _file_sha1 file

The SHA1 checksum value $upload _FILE_SHA1_UC capital letters

File CRC32 value represented by $upload _FILE_CRC32 16 binary

$upload _file_size File Size

$upload _file_number The file number in the request body

These field values are calculated after the file has been successfully uploaded.

Upload_cleanup If an error such as 400 404 499 500-505 appears, delete the uploaded file

Upload_buffer_size Upload buffer size

Upload_max_part_header_len Specifies the maximum length byte of the head section.

UPLOAD_MAX_FILE_SIZE Specifies the maximum size and soft limit for uploading files. Client_max_body_size hard limit.

Upload_limit_rate upload speed limit, if set to 0 means no limit.

Upload_max_output_body_len exceeds this size and will report 403 errors (Request entity too large).

UPLOAD_TAME_ARRAYS Specifies whether square brackets for file field names are deleted

Upload_pass_args whether the parameter is forwarded.

Three. Nginx Configuration

#wgethttp//www.nginx.org/download/nginx-1.2.2.tar.gz# wgethttp//www.grid.net.ru/nginx/download/nginx_upload_module-2.2.0.tar.gz# TarZXVF nginx_upload_module-2.2.0.Tar. gz-c. /software/# TarZXVF nginx_upload_module-2.2.0.Tar. gz-c. /software/# ./configure--prefix=/usr/local/nginx--add-module=. /nginx_upload_module-2.2.0--with-http_secure_link_module# Make#  Make Install# VINginx.confuser www-data;worker_processes -; Error_log logs/Error.log notice;working_directory/usr/local/nginx;events {worker_connections1024x768;} HTTP {include Mime.types;default_type application/octet-Stream;root/www/web/Upload;server {Listen the; server_name192.168.41.129; Error_page405= $@405;//Handling 405 Errors Location/{index index.html index.htm index.php;} Location @405{root/www/web/upload;} Location~\.php$ {try_files $uri/404. Html;fastcgi_pass127.0.0.1:9000; Fastcgi_index index.php;fastcgi_param script_filename $document _root$fastcgi_script_name;include/etc/nginx/Fastcgi_params;} Client_max_body_size 100m;# upload page submitted to this locationlocation/Upload {# file after uploading to the back end of the PHP code processing upload_pass @test; # temporary storage location of uploaded files, directory is hashed, should exist subdirectory 01 2 3 4 5 6 7 8 9Upload_store/www/web/upload/tmp1; upload_store_access user:r;# Set the field of the 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;# indicates the backend MD5 value and file size for uploading files Upload_aggregate_form_field"${UPLOAD_FIELD_NAME}_MD5"$upload _file_md5;upload_aggregate_form_field"${upload_field_name}_size"$upload _file_size;# indicates that the parameter is going to the back end, and can be represented by a regular expression Upload_pass_form_field"^submit$|^description$"; Upload_pass_args on;} # Move the request to the back-end address processing location @test {rewrite^ (. *) $/test.php Last;}}}

Nginx Upload Module Upload

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.