Openresty + nginx-upload-module Support File upload

Source: Internet
Author: User

1. Package download

openresty-1.13.6.1 https://openresty.org/download/openresty-1.13.6.1.tar.gz

nginx-upload-module-2.2 because the original author has been a long time not updated, originally from the original author GitHub download, when compiling openresty error: Ngx_http_upload_module.c:14:17:fatal Error:md5.h:no such file or directory

Later found a usable fork version of Https://github.com/Austinb/nginx-upload-module2. Compile

(1) respectively decompression openresty-1.13.6.1.tar.gz and Nginx-upload-module-2.2.zip

(2) Execute/sdf/slb/openresty-1.13.6.1#./configure--prefix=/sdf/slb/openresty --add-module=/sdf/slb/nginx_upload_ module-2.2.0

3. Configure 3.1 nginx.conf

Need to configure Upload_pass as a file after the upload of the return processing, we used this time is a Golang write a simple HTTP service.

Worker_processes 20;error_log logs/error.log notice;events {worker_connections 1024;}    HTTP {include mime.types;    Default_type Application/octet-stream;        server {listen 8081;        Client_max_body_size 100m; # Upload form should is submitted to this location Location/upload {file uploaded action # Pass altered request Body to this location upload_pass/test/my; return after file upload # Store files to this directory # Th E directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist Upload_store/sdf/slb/store 1; The path to the file store, first Manually created 0 1 2 3 4 5 6 7 8 91 A total of 10 folders # allow uploaded. Files to is read only by user Upload_st            Ore_access USER:RW;            # Set specified 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 _f            ILE_MD5;            Upload_aggregate_form_field "${upload_field_name}_size" $upload _file_size;        Upload_pass_form_field "^submit$|^description$"; # Pass altered request body to a backend location/test/my {proxy_pass http://192.168.            25.84:50,000; local One service} location/site {root html; Index upload.html; support for file upload static page}}}

Local Service test.go source code, run as Nohup go run Test.go &, will start a http://127.0.0.1:50000 service, which includes a/test/my interface, return upload success string.

Test Project Test.gopackage mainimport ("io" "Log" "Net/http") func my (w http. Responsewriter, R *http. Request) {io. WriteString (W, "Upload success")}func Main () {http. Handlefunc ("/test/my", my) Err: = http. Listenandserve (": 50000", nil) if err! = Nil {log. Fatal ("Listen Server:", err.) Error ())}}

 

3.2 Configure static page access as a portal for file uploads

To build openresty static page access, please refer to Http://www.cnblogs.com/lujiango/p/9001006.html#_lab2_4_0

The contents of the upload.html file are as follows: Please note that the action= "/upload" is corresponding to the location/upload{in nginx.conf.

The page is as follows:

3.3 File Upload

Access Http:192.168.25.84:8081/site or http:192.168.25.84:8081/site/upload.html

Can enter the File Upload portal page, select File Upload, the following is the successful file upload.

At this point, the file storage location in NGINX.CONF configuration has the following files:

0000000010 and 0000000020 of these are uploaded files.

Note: When uploading the file error:/sdf/slb/store/6/0000000006 "for" 89629.log "(13:permission denied), this is the problem of Nginx permissions, you can refer to https:// www.ruby-forum.com/topic/1379755

X. References

https://www.ruby-forum.com/topic/1379755

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

Https://github.com/Austinb/nginx-upload-module/blob/2.2/nginx.conf

Openresty + nginx-upload-module Support File 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.