前段时间做一个项目,需要上传文件,差不多需要20M左右,普通用php处理会比较麻烦,经常超时,而且大量占用资源。于是搜索了下,决定用nginx的upload上传模块来处理。

你可以在这里:http://www.grid.net.ru/nginx/upload.en.html 获取源码。下载以后需要重新编译nginx

1
2
3
./configure –add-module=/usr/local/nginx_upload_module-*
make
make install

重启nginx即可
以下是我的nginx配置文件

前端页面提交的时候直接提交到 http://test.local/upload 即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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;
        }
 
}

大概解释一下每个参数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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 "^.*$";

Nginx的Upload上传模块的更多相关文章

  1. nginx上传模块nginx_upload_module和nginx_uploadprogress_module模块进度显示,如何传递GET参数等。

    ownload:http://www.grid.net.ru/nginx/download/nginx_upload_module-2.2.0.tar.gzconfigure and make : . ...

  2. Nginx Upload Module 上传模块

    传统站点在处理文件上传请求时,普遍使用后端编程语言处理,如:Java.PHP.Python.Ruby等.今天给大家介绍Nginx的一个模块,Upload Module上传模块,此模块的原理是先把用户上 ...

  3. 解决nginx上传模块nginx_upload_module传递GET参数

    解决nginx上传模块nginx_upload_module传递GET参数的方法总结 最近用户反映我们的系统只能上传50M大小的文件, 希望能够支持上传更大的文件. 很显然PHP无法轻易实现大文件上传 ...

  4. 基于SpringBoot从零构建博客网站 - 设计可扩展上传模块和开发修改头像密码功能

    上传模块在web开发中是很常见的功能也是很重要的功能,在web应用中需要上传的可以是图片.pdf.压缩包等其它类型的文件,同时对于图片可能需要回显,对于其它文件要能够支持下载等.在守望博客系统中对于上 ...

  5. nginx实现文件上传和下载

    nginx实现文件上传和下载 发布时间:2020-06-05 16:45:27 来源:亿速云 阅读:156 作者:Leah 栏目:系统运维 这篇文章给大家分享的是nginx实现文件上传和下载的方法.小 ...

  6. 基于SqlSugar的开发框架循序渐进介绍(7)-- 在文件上传模块中采用选项模式【Options】处理常规上传和FTP文件上传

    在基于SqlSugar的开发框架的服务层中处理文件上传的时候,我们一般有两种处理方式,一种是常规的把文件存储在本地文件系统中,一种是通过FTP方式存储到指定的FTP服务器上.这种处理应该由程序进行配置 ...

  7. UEditor独立图片、文件上传模块

    百度的UEditor编辑器的强大之处不用多说,但是有时候我们只想用他的文件.图片上传模块,不想把这个编辑器加载出来,话不多说,直接上实现代码: 引用文件: <script src="~ ...

  8. Struts Upload上传文件

    1.Unable to find 'struts.multipart.saveDir' property setting. Defaulting to javax.servlet.context.te ...

  9. h5 + nginx + php 视频上传之突破文件大小受限的解决办法

    一.环境: CentOS 6.8 nginx 1.8.0 php 7.0.10 二.背景 基于 nginx + php 的 h5 项目,上传视频的时候,如果视频太大,会上传失败. 三.正文 一份视频传 ...

随机推荐

  1. window系统查看端口被哪个进程占用

    ---恢复内容开始--- 1.在cmd窗口运行 netstat -ano | findstr 1099 找到进程PID 8408 杀死进程:taskkill -F -PID 8408 2.另外还找到进 ...

  2. iOS: 消息通信中的Notification&KVO

    iOS: 消息通信中的Notification&KVO 在 iOS: MVC 中,我贴了张经典图: 其中的Model向Controller通信的Noification&KVO为何物呢? ...

  3. iOS中构造函数与析构函数

    一.构造函数 在OC中凡是已init开头的函数我们都称之为构造函数,在声明构造函数的时候,不带参数的一般直接声明为“-(id)init”,带参数的一般声明为“-(id)initWith...”. 1 ...

  4. The Contiki build system 编译系统

    The Contiki build system======================== The Contiki build system is designed to make it eas ...

  5. oracle安装报错2

    [oracle@centos1 database]$ ./runInstaller Starting Oracle Universal Installer... Checking installer ...

  6. linux下ifconfig, DNS以及route配置

    转载:http://blog.csdn.net/wangjingfei/article/details/5283632/ 熟悉使用ifconfig 会非常方便. ifconfig eth0 新ip 然 ...

  7. Android 中的接口回调

    http://blog.csdn.net/wangjinyu501/article/details/22052187   在Android中到处可见接口回调机制,尤其是UI事件处理方面.举一个最常见的 ...

  8. 【转】Linux下Android ADB驱动安装详解

    原文网址:http://blog.csdn.net/zhenwenxian/article/details/5901350 Linux下Android ADB驱动安装详解 概述 最近由于内置的合作商比 ...

  9. 在CDHtmlDialog中处理WindowClosing

    要截获window.close(),就得截获CDHtmlDialog的WindowClosing.以下是示例代码: // header DECLARE_EVENTSINK_MAP() void Win ...

  10. 漏洞:WebRTC 泄漏用户IP

    WebRTC又称为“网页即时通信”,是一组API函数,它经过W3C组织的认证,支持浏览器之间的语音通话.视频聊天和P2P模式分享文件.      这个协议主要包括:getUserMedia,RTCPe ...