1.Nginx 上传

  • Nginx 依赖包下载

    # wget http://www.nginx.org/download/nginx-1.2.2.tar.gzinx

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

    # wget http://nchc.dl.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz

    # wget http://zlib.net/zlib-1.2.8.tar.gz

    # tar -zxvf nginx-1.2.2.tar.gz -C software

    # tar zxvf nginx_upload_module-2.2.0.tar.gz -C software/

    # tar zxvf pcre-8.37.tar.gz -C software/

    # tar zxvf zlib-1.2.8.tar.gz -C software/

  • Nginx  Configure

    # ./configure --prefix=/usr/local/nginx --add-module=../nginx_upload_module-2.2.0 --with-http_secure_link_module --with-pcre=/home/ubuntu/software/pcre-8.37 --with-zlib=/home/ubuntu/software/zlib-1.2.8

  • Nginx  Make

    # make

    make过程中,注意查看过程是否出错

    

    • 错误1:

    

    解决:

      Openssl 安装

      检查是否已安装openssl:

      sudo apt-get install openssl

      如果没有安装执行以下操作:
      sudo apt-get install libssl-dev
      sudo apt-get install libssl0.9.8

    • 错误2:

    

    解决:

    Just replace "int
result;" by "__attribute__((__unused__)) int result;".

  • Nginx  Make Install

    # make install

  • Nginx  配置 upload

    修改/usr/local/nginx/conf/nginx.conf

    # 上传大小限制(包括所有内容)

    client_max_body_size
100m;

    # 上传path配置

    location /upload {

    #
转到后台处理URL

      upload_pass  
/uploadHandle;

      # 文件上传以后转交给后端的php代码处理

      # 这个位置是否是文章上传成功到指定目录后
戳发后台处理的地址

      upload_pass /uploadBackendDispose;

    #
临时保存路径

    #
可以使用散列

    upload_store
/tmp/nginx_upload;

    #
上传文件的权限,rw表示读写 r只读

     upload_store_access
user:rw;

    #
这里写入http报头,pass到后台页面后能获取这里set的报头字段

    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模块自动生成的一些信息,如文件大小与文件md5值

    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_pass_form_field "^.*$";

    #
每秒字节速度控制,0表示不受控制,默认0

    upload_limit_rate
0;

    #
如果pass页面是以下状态码,就删除此次上传的临时文件

    upload_cleanup
400 404 499 500-505;

    }

    # 将请求转到后端的地址处理

    location /uploadBackendDispose
{
           proxy_pass
http://localhost:10000/nginx_file_upload;

    }

  • Nginx  启动

    直接运行sudo
/usr/local/nginx/sbin/nginx

  • Nginx  上传测试POST

    Html代码

    <html>

    <head>

    <title>Test upload</title>

    </head>

    <body>

    <h2>Select files to upload</h2>

    <form enctype="multipart/form-data" action="http://52.77.234.86/upload"
method="post">

    <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="submit111" value="Upload">

    <input type="hidden"
name="user1" value="value1">

    <input type="hidden"
name="user2" value="value2">

    <input type="hidden"
name="user3" value="value3">

    </form>

    </body>

    </html>

    可在服务器的/tmp/nginx_upload目录在看到上传的文件

    这部分参数为上传到后台的处理参数:

    

  • Nginx  上传文件附带参数特别说明

  1. Nginx.conf中设置upload_pass_form_field

    # 允许所有的字段

    upload_pass_form_field
"^.*$";

  2. Nginx.conf中设置upload_pass_form_field

    在上传表单中增加上传字段

    <input type="submit" name="submit111" value="Upload">

    <input type="hidden" name="user1" value="value1">

    <input type="hidden" name="user2" value="value2">

    <input type="hidden" name="user3" value="value3">

  3. Nginx回调后台的url可接受到以下参数:

    uri:/nginx_file_upload

    headers:{'Content-Length':
'1306', 'Accept-Language': 'zh-CN', 'Accept-Encoding': 'gzip, deflate',
'Connection': 'close', 'Accept': 'text/html, application/xhtml+xml, */*',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like
Gecko', 'Dnt': '1', 'Host': 'localhost:10000', 'Cache-Control': 'no-cache',
'Content-Type': 'multipart/form-data;
boundary=---------------------------7df1e01d20270'}

    body_arguments:{"file3":[""],"file2":[""],"file6":[""],"file5":[""],"file4":[""],"file1_content_type":["image\/jpeg"],"file1_md5":["fafa5efeaf3cbe3b23b2748d13e629a1"],"submit111":["Upload"],"file1_name":["Tulips.jpg"],"test":["value"],"file1_path":["\/tmp\/nginx_upload\/0000000001"],"file1_size":["620888"]}

    body:-----------------------------7df1e01d20270

    Content-Disposition:
form-data; name="file1_name"

    Tulips.jpg

    -----------------------------7df1e01d20270

    Content-Disposition:
form-data; name="file1_content_type"

    image/jpeg

    -----------------------------7df1e01d20270

    Content-Disposition:
form-data; name="file1_path"

    /tmp/nginx_upload/0000000001

    -----------------------------7df1e01d20270

    Content-Disposition:
form-data; name="file1_md5"

    fafa5efeaf3cbe3b23b2748d13e629a1

    -----------------------------7df1e01d20270

    Content-Disposition:
form-data; name="file1_size"

    620888

    -----------------------------7df1e01d20270

    Content-Disposition:
form-data; name="file2"

    -----------------------------7df1e01d20270

    Content-Disposition:
form-data; name="file3"

    -----------------------------7df1e01d20270

    Content-Disposition:
form-data; name="file4"

    -----------------------------7df1e01d20270

    Content-Disposition:
form-data; name="file5"

    -----------------------------7df1e01d20270

    Content-Disposition:
form-data; name="file6"

    -----------------------------7df1e01d20270

    Content-Disposition:
form-data; name="submit111"

    Upload

    -----------------------------7df1e01d20270

    Content-Disposition:
form-data; name="test"

    value

    -----------------------------7df1e01d20270--

    [WARNING] [P31366]
T140497047279408] 2015-12-24 15:06:39] nginx_file_upload, args:() kwargs:
{u'file3':
'', u'file2': '', u'file6': '', u'file5': '', u'file4': '',
u'file1_content_type':
'image/jpeg', u'file1_md5': 'fafa5efeaf3cbe3b23b2748d13e629a1', u'submit111':
'Upload',
u'file1_name':
'Tulips.jpg', u'test1': 'value1', u'test2': 'value2', u'file1_path':
'/tmp/nginx_upload/0000000001', u'file1_size': '620888'}

2.Nginx 下载

  • Nginx  配置 download

    修改/usr/local/nginx/conf/nginx.conf

    server {

   listen  20150;

      root
/tmp/nginx_upload;

    }

    

    /tmp/nginx_upload为刚才nginx上传的文件目录,这样就可以实现文件的上传和下载

    如果涉及到文件后缀名的问题,可以使用python等脚本语言,接受nginx的上传url,然后对上传的文件进行处理,达到逻辑需求

Nginx文件上传下载实现与文件管理的更多相关文章

  1. C# 文件上传下载功能实现 文件管理引擎开发

    Prepare 本文将使用一个NuGet公开的组件技术来实现一个服务器端的文件管理引擎,提供了一些简单的API,来方便的实现文件引擎来对您自己的软件系统的文件进行管理. 在Visual Studio ...

  2. Nginx + Lua搭建文件上传下载服务

    收录待用,修改转载已取得腾讯云授权 最新腾讯云技术公开课直播,提问腾讯W3C代表,如何从小白成为技术专家?点击了解活动详情 作者 | 庄进发 编辑 | 迷鹿 庄进发,信息安全部后台开发工程师,主要负责 ...

  3. FastDFS实现文件上传下载实战

    正好,淘淘商城讲这一块的时候,我又想起来当时老徐让我写过一个关于实现FastDFS实现文件上传下载的使用文档,当时结合我们的ITOO的视频系统和毕业论文系统,整理了一下,有根据网上查到的知识,总结了一 ...

  4. Java 客户端操作 FastDFS 实现文件上传下载替换删除

    FastDFS 的作者余庆先生已经为我们开发好了 Java 对应的 SDK.这里需要解释一下:作者余庆并没有及时更新最新的 Java SDK 至 Maven 中央仓库,目前中央仓库最新版仍旧是 1.2 ...

  5. 一、手把手教你docker搭建fastDFS文件上传下载服务器

    在搭建fastDFS文件上传下载服务器之前,你需要准备的有一个可连接的linux服务器,并且该linux服务器上已经安装了docker,若还有没安装docker的,先百度自行安装docker. 1.执 ...

  6. Struts的文件上传下载

    Struts的文件上传下载 1.文件上传 Struts2的文件上传也是使用fileUpload的组件,这个组默认是集合在框架里面的.且是使用拦截器:<interceptor name=" ...

  7. Android okHttp网络请求之文件上传下载

    前言: 前面介绍了基于okHttp的get.post基本使用(http://www.cnblogs.com/whoislcj/p/5526431.html),今天来实现一下基于okHttp的文件上传. ...

  8. Selenium2学习-039-WebUI自动化实战实例-文件上传下载

    通常在 WebUI 自动化测试过程中必然会涉及到文件上传的自动化测试需求,而开发在进行相应的技术实现是不同的,粗略可划分为两类:input标签类(类型为file)和非input标签类(例如:div.a ...

  9. 艺萌文件上传下载及自动更新系统(基于networkComms开源TCP通信框架)

    1.艺萌文件上传下载及自动更新系统,基于Winform技术,采用CS架构,开发工具为vs2010,.net2.0版本(可以很容易升级为3.5和4.0版本)开发语言c#. 本系统主要帮助客户学习基于TC ...

随机推荐

  1. 在cmd中显示mysql -uroot-proot 不是命令

    这个代码的意思是打开mysql,用户名为root,密码也是root 解决办法:方法一:首先要进入mysql的bin目录下,再执行. 密码错了,重新输入密码,没有密码嘛

  2. oracle 求班级平均分

    select * from ( selectclass 班级,subject,avg(grade) avg_gradefrom student_score group by class,subject ...

  3. 怎样查看lInux系统中的所有运行进程

    可以使用ps命令.它能显示当前运行中进程的相关信息,包括进程的PID.Linux和UNIX都支持ps命令,显示所有运行中进程的相关信息. ps命令能提供一份当前进程的快照.如果想状态可以自动刷新,可以 ...

  4. 映射文件中增删改查标签中的parameterType和resultType

    parameterType:指定输入参数类型,mybatis通过ognl从输入对象中获取参数值拼接在sql中. resultType:指定输出结果类型,mybatis将sql查询结果的一行记录数据映射 ...

  5. 服务器上创建git仓库

    1. 在服务器上 su - git ,切换用户 2. 创建一个目录    mkdir test.git ,请注意带上 .git 扩展 3. 切换进入此目录,git init --bare  ,初始化裸 ...

  6. Tips and Examples Using FNDLOAD (DOC ID 735338.1)

    In this Document Goal Solution Some Tips About FNDLOAD Some sample examples Diagnostics & Utilit ...

  7. [翻译]Component Registration in Script System 在脚本系统中注册组件

    Component Registration in Script System 在脚本系统中注册组件   To refer to our component from a script, the cl ...

  8. JavaScript实现的3D球面标签云效果

    这个效果都是由 FLASH 实现的,能不能由 JavaScript 实现呢? 我们也十分喜欢这个效果,就花了一些时间写出来了,如图所示: 效果预览点这里:http://www.miaov.com/mi ...

  9. VUE 学习笔记 一 指令

    1.声明式渲染 v-bind 特性被称为指令.指令带有前缀 v-,以表示它们是 Vue 提供的特殊特性 <div id='app'> <span v-bind:title=" ...

  10. SQL表连接查询inner join left join right join full join ...

    一.最常见的连接查询 select  s.name,m.mark from student s,mark m  where s.id=m.studentid. 二.内连接-inner join sel ...