nginx上传模块下载安装

Nginx下载地址,英文文档

http://happyqing.iteye.com/blog/1806478

上传模块下载地址

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

http://www.grid.net.ru/nginx/download/nginx_upload_module-2.2.0.tar.gz

Nginx-1.3.X,Nginx-1.4.X安装nginx_upload_module-2.2.0.tar.gz会有点问题,报

/opt/nginx_upload_module-2.2.0/ngx_http_upload_module.c: In function ‘ngx_http_read_upload_client_request_body’:
/opt/nginx_upload_module-2.2.0/ngx_http_upload_module.c:2628: 错误:‘ngx_http_request_body_t’ 没有名为 ‘to_write’ 的成员

选择Nginx-1.2.X的就没问题。

安装方法

cd <path to nginx sources>
./configure --add-module=<path to upload module sources>
make
make install

[root@dev opt]# tar xvzf nginx_upload_module-2.2.0.tar.gz

[root@dev opt]# cd /opt/nginx-1.2.9

[root@dev nginx-1.2.9]# ./configure --add-module=/opt/nginx_upload_module-2.2.0

[root@dev nginx-1.2.9]# make

[root@dev nginx-1.2.9]# make install

上传会涉及权限问题,nginx要写临时文件,要注意nginx的启动用户是否具有对相应目录的操作权限

有问题看日志

nginx.conf

user root

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>

 文档参考:

http://blog.csdn.net/langeldep/article/details/8755613

http://www.ttlsa.com/html/1448.html

猜你喜欢

转载自happyqing.iteye.com/blog/1956639
今日推荐