nginx上传模块nginx_upload_module使用

1、安装模块

1cd/data/software
2wget http://www.grid.net.ru/nginx/download/nginx_upload_module-2.0.12.tar.gz
3tarzxvf nginx_upload_module-2.0.12.tar.gz

进入nginx源码目录

1./configure --with-http_stub_status_module \ --add-module=/data/software/nginx_upload_module-2.0.12
2make#新增模块,不用make install
3mv/usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
4cp./objs/nginx /usr/local/nginx/sbin/nginx

2、修改配置文件,在server中增加一下内容

01location /upload {
02upload_pass /info.php;#上传完成后端接受处理文件
03upload_store /data/uptmp;#上传文件夹
04upload_limit_rate 1024k;# 限制上传速度
05upload_set_form_field"${upload_field_name}_name"$upload_file_name;#文件名称
06upload_set_form_field"${upload_field_name}_content_type"$upload_content_type;#文件类型
07upload_set_form_field"${upload_field_name}_path"$upload_tmp_path;#上传到的路径
08upload_aggregate_form_field"${upload_field_name}_md5"$upload_file_md5;#md5
09upload_aggregate_form_field"${upload_field_name}_size"$upload_file_size;#文件大小
10upload_pass_form_field"^submit$|^description$";
11#如果希望把所有的表单字段都传给后端可以用upload_pass_form_field "^.*$";
12}

3、前端代码

up.html

01<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
02<htmlxmlns="http://www.w3.org/1999/xhtml">
03<head>
04<title>无标题文档</title>
05</head>
06<body>
07<metahttp-equiv="Content-Type"content="text/html; charset=utf-8"/>
08<formname="upload"method="POST"enctype="multipart/form-data"action="/upload"><!--提交到上面的/upload-->
09<inputtype="file"name="file">
10
11<inputtype="submit"name="submit"value="Upload">
12</form>
13</body>
14</html>

info.php

1<?php
2header("Content-Type:text/html; charset=utf-8");
3print_r($_POST);

上传会返回如下图数据

from:http://foooy.me/nginx/158.html