nginx上传模块nginx_upload_module使用

2012-7-27 foooy Nginx

以下在nginx1.2.7上测试通过

1、安装模块

cd /data/software
wget http://www.grid.net.ru/nginx/download/nginx_upload_module-2.0.12.tar.gz
或者在https://github.com/vkholodkov/nginx-upload-module/tree/2.2下载
tar zxvf nginx_upload_module-2.0.12.tar.gz
进入nginx源码目录 
./configure --with-http_stub_status_module \ --add-module=/data/software/nginx_upload_module-2.0.12
make#新增模块,不用make install
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
cp ./objs/nginx /usr/local/nginx/sbin/nginx

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

        location /upload {
            upload_pass   /info.php;#上传完成后端接受处理文件
            upload_store /data/uptmp;#上传文件夹
            upload_limit_rate 1024k;# 限制上传速度
            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;#md5
            upload_aggregate_form_field "${upload_field_name}_size" $upload_file_size;#文件大小
            upload_pass_form_field "^submit$|^description$";
            #如果希望把所有的表单字段都传给后端可以用upload_pass_form_field "^.*$";
        }

 

3、前端代码

up.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题文档</title>
</head>
<body>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<form name="upload" method="POST" enctype="multipart/form-data" action="/upload"><!--提交到上面的/upload-->
<input type="file" name="file"><br>
<input type="submit" name="submit" value="Upload">
</form>
</body>
</html>
info.php
<?php
    header("Content-Type:text/html; charset=utf-8");
    print_r($_POST);

上传会返回如下图数据

点击查看原图

标签: linux centos api

评论:

刘馨
2015-06-08 14:25
我参考 https://github.com/hongzhidao/nginx-upload-module 的\nginx-upload-module 文档
再结合 此中文文件 我是这样做的
1。  location /upload {
        # Pass altered request body to this location
        upload_pass   @uploadBackendDispose;   //这个位置是否是文章上传成功到指定目录后 戳发后台处理的地址
        upload_store /tmp/upload 1;

2.     location @uploadBackendDispose {
        proxy_pass http://192.168.1.215:8080

3.  上传页面是这样配的

<form method="POST" action='192.168.1.215:80/upload' name="postForm" enctype="multipart/form-data">
选择文件1:
<input type="file"name="filename1"/>

4. 我在页面点击上传,浏览器地址显示  192.168.1.215:80/upload 404错误

6.  如果 upload_pass 是文章上传成功到指定目录后 戳发后台处理的地址,我想戳发  /FileUpload/upload 应该怎么配
WEB 工程 FileUpload 我这样配的
      <servlet>
        <description>UploadHttpServlet</description>
        <display-name>UploadHttpServlet</display-name>
        <servlet-name>UploadHttpServlet</ servlet-name>
        <servlet-class>fileUpload.UploadHttpServlet</ servlet-class>
      </ servlet>
    <servlet-mapping>
        <servlet-name>UploadHttpServlet</ servlet-name>
        <url-pattern>/upload</url-pattern>
    </ servlet-mapping>

请给予帮助 我的QQ:2383195506
foooy
2015-10-13 19:51
@刘馨:插件没安装成功,或者节点有问题
pk
2016-05-13 14:47
@刘馨:表单  action='http://192.168.1.215:80/upload'
刘馨
2015-06-08 12:11
模仿你的大作没有上传成功,能否提供帮助。我的QQ:2383195506
foooy
2015-10-13 19:50
@刘馨:是不是插件没安装成功

发表评论:

Powered by emlog 鄂ICP备14000186号-1 sitemap