Nginx的Upload上传模块
2012-05-24 11:04
591 查看
本文来源:http://zuroc.42qu.com/10105260
前段时间做一个项目,需要上传文件,差不多需要20M左右,普通用php处理会比较麻烦,经常超时,而且大量占用资源。于是搜索了下,决定用nginx的upload上传模块来处理。
你可以在这里:http://www.grid.net.ru/nginx/upload.en.html
获取源码。下载以后需要重新编译nginx./configure –add-module=/usr/local/nginx_upload_module-*makemake install
重启nginx即可
以下是我的nginx配置文件
前端页面提交的时候直接提交到 http://test.local/upload 即可server{ listen 80; server_name test.local; index index.php index.shtml index.htm index.html; root /data/app/test.local/wwwroot; access_log off;
location /upload { upload_pass /index.php?c=uploader&a=upload_server; upload_cleanup 400 404 499 500-505; upload_store /data/app/test.local/upload_tmp; upload_store_access user:r; upload_limit_rate 128k; 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 "^.*$"; }
location ~ .*\.php?$ { include fastcgi_params; }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; }
location ~ .*\.(js|css)?$ { expires 1d; }
}
大概解释一下每个参数upload_pass 指明了需要后续处理的php地址
upload_cleanup 如果php出现400 404 499 500-505之类的错误,则删除上传的文件
upload_store 上传文件存放地址
upload_store_access 上传文件的访问权限,user:r是指用户可读
upload_limit_rate 上传限速,如果设置为0则表示不限制
upload_set_form_field 设定额外的表单字段。这里有几个可用的变量:$upload_file_name 文件原始名字$upload_field_name 表单的name值$upload_content_type 文件的类型$upload_tmp_path 文件上传后的地址
upload_aggregate_form_field 额外的变量,在上传成功后生成$upload_file_md5 文件的MD5校验值$upload_file_size 文件大小
upload_pass_form_field 从表单原样转到后端的参数,可以正则表达式表示官方的例子是upload_pass_form_field "^submit$|^description$";意思是把submit,description这两个字段也原样通过upload_pass传递到后端php处理。如果希望把所有的表单字段都传给后端可以用upload_pass_form_field "^.*$";
这样,在php端,直接可以用$_POST去接收信息并进行处理了。
http://anerg.com/read.php?55
前段时间做一个项目,需要上传文件,差不多需要20M左右,普通用php处理会比较麻烦,经常超时,而且大量占用资源。于是搜索了下,决定用nginx的upload上传模块来处理。
你可以在这里:http://www.grid.net.ru/nginx/upload.en.html
获取源码。下载以后需要重新编译nginx./configure –add-module=/usr/local/nginx_upload_module-*makemake install
重启nginx即可
以下是我的nginx配置文件
前端页面提交的时候直接提交到 http://test.local/upload 即可server{ listen 80; server_name test.local; index index.php index.shtml index.htm index.html; root /data/app/test.local/wwwroot; access_log off;
location /upload { upload_pass /index.php?c=uploader&a=upload_server; upload_cleanup 400 404 499 500-505; upload_store /data/app/test.local/upload_tmp; upload_store_access user:r; upload_limit_rate 128k; 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 "^.*$"; }
location ~ .*\.php?$ { include fastcgi_params; }
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; }
location ~ .*\.(js|css)?$ { expires 1d; }
}
大概解释一下每个参数upload_pass 指明了需要后续处理的php地址
upload_cleanup 如果php出现400 404 499 500-505之类的错误,则删除上传的文件
upload_store 上传文件存放地址
upload_store_access 上传文件的访问权限,user:r是指用户可读
upload_limit_rate 上传限速,如果设置为0则表示不限制
upload_set_form_field 设定额外的表单字段。这里有几个可用的变量:$upload_file_name 文件原始名字$upload_field_name 表单的name值$upload_content_type 文件的类型$upload_tmp_path 文件上传后的地址
upload_aggregate_form_field 额外的变量,在上传成功后生成$upload_file_md5 文件的MD5校验值$upload_file_size 文件大小
upload_pass_form_field 从表单原样转到后端的参数,可以正则表达式表示官方的例子是upload_pass_form_field "^submit$|^description$";意思是把submit,description这两个字段也原样通过upload_pass传递到后端php处理。如果希望把所有的表单字段都传给后端可以用upload_pass_form_field "^.*$";
这样,在php端,直接可以用$_POST去接收信息并进行处理了。
http://anerg.com/read.php?55
相关文章推荐
- nginx上传模块—nginx upload module
- nginx上传模块nginx_upload_module和nginx_uploadprogress_module模块进度显示,如何传递GET参数等。
- Nginx Upload Module 上传模块
- nginx上传模块nginx_upload_module原理、安装及使用教程
- nginx上传模块—nginx upload module-
- nginx-upload-module文件上传模块问题处理
- nginx上传模块---nginx upload module
- nginx上传模块nginx_upload_module和nginx_uploadprogress_module模块进度显示,如何传递GET参数等。
- Nginx的上传模块NginxHttpUploadProgressModule
- Nginx的Upload上传模块
- 解决nginx上传模块nginx_upload_module传递GET参数
- nginx上传模块nginx_upload_module使用
- smartupload -- 批量上传模块
- 利用Nginx的上传模块和上传进度模块实现网页上传文件
- uploadFile+nginx实现上传图片(Windows/Linux均可用)
- php+nginx+uploadfiy上传大文件不能超过1M的解决办法
- 分布式文件系统 - FastDFS 配置 Nginx 模块及上传测试
- Nginx+PHP+Swfupload 上传大文件
- Nginx+upload+lua 简单的文件上传
- 文章15:Nginx upload 模块(一)