---
title: "使用 nginx_upload_module 上传文件"
author: "willeager"
date: "2014-05-09T21:12:16Z"
tags: []
categories: ["编程语言"]
slug: "nginx-upload-module"
draft: false
lastmod: "2014-05-09T21:25:36Z"
id: 2064491
url: "https://willeager.iteye.com/blog/2064491"
---

使用 nginx\_upload\_module上传大附件

由于PHP会上传超时，不能限速！

php.ini中的配置对nginx\_upload\_module没有影响。

如果要上传大文件，可以在nginx.conf中的http部分添加一行：

client\_max\_body\_size 50m;

另外还要进行上传的配置：

location = /suibian-shezhi.htm {

                upload\_pass   @utest; 

 

                upload\_store /tmp/nginx\_upload;

 

                upload\_store\_access user:rw;

 

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

 

                #upload\_limit\_rate 1000k; (用于限速)

 

                upload\_cleanup 400 404 499 500-505;

        }

        location @utest{

                rewrite ^(.\*)$ /index.php last;

        }

 

 如何安装：

之前已安装nginx但没有装这个module

重新安装过。

1.下载nginx wget http://nginx.org/download/nginx-1.3.0.tar.gz

2, 下载nginx upload module模块

wget http://www.grid.net.ru/nginx/download/nginx\_upload\_module-2.2.0.tar.gz

3\. 解压缩nginx\_upload\_module 这个解压就可以了，不需要安装什么的

4\. ./configure --prefix=.... --add-module=../nginx\_upload\_module-2.2.0/

注意要添加--add-module 可以是相对路径，也可以是绝对路径

 

 

相关配置：

注意：需要修改php.ini以下参数

file\_uploads on 是否允许通过http上传

upload\_max\_filesize 8m 允许上传文件的最大大小

post\_max\_size 8m 通过表单POST给php所能接收的最大值

另外nginx.conf中设置上传文件大小

upload\_max\_file\_size 软限制

 

client\_max\_body\_size 硬限制