再次优化NGINX+php-fpm上传

上次写了一篇nginx+php-fpm优化上传,一位博友留言介绍了,第三方nginx upload module

http://www.grid.net.ru/nginx/upload.en.html

看了一下,功能蛮强大的,所以就记录下来·基本没什么变化,在原有的例子上稍加了下修改,加了一个限速功能。在 0.8.X 版本上编译出出错,他官方也有写:

For nginx versions other than 0.7.44-51

但是我在最新版本 nginx-0.7.67.tar.gz 编译也没问题。 下载nginx:wget http://www.nginx.org/download/nginx-0.7.67.tar.gz 下载模块:wget http://www.grid.net.ru/nginx/download/nginx_upload_module-2.0.12.tar.gz 1.下载编译安装nginx_upload_module

nginx $> tar zxvf nginx-0.7.67.tar.gz
nginx $> tar zxvf nginx_upload_module-2.0.12.tar.gz
nginx $> cd nginx-0.7.67
#关掉不需要的模块,节省资源开支俗话说越简洁越稳定~
nginx $> ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --without-http_memcached_module --without-http_empty_gif_module --without-mail_pop3_module  --without-mail_imap_module --without-mail_smtp_module --add-module=/root/nginx_upload_module-2.0.12
nginx $> make
nginx $> make install

2.创建配置文件:

nginx $> cd /usr/local/nginx/conf
nginx $> vim nginx.conf
user    www    www;
worker_processes  1;

error_log  logs/error.log notice;
pid        logs/nginx.pid;

working_directory /usr/local/nginx;

worker_rlimit_nofile    65535;
events {
    use epoll;
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    client_max_body_size 1024m;
   server {
        listen       80;
        server_name     192.168.6.162;
        index   index.html index.htm index.php;
        root    /var/www;

        # Upload form should be submitted to this location
        location /upload {
            # Pass altered request body to this location
            upload_pass   /upload.php;

            # Store files to this directory
            # The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist
            upload_store /var/www/webdata;

            # Allow uploaded files to be read only by user
            upload_store_access user:r;
            # 限制上传速度
            upload_limit_rate 128k;

            # Set specified fields in request body
            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;

            # Inform backend about hash and size of a file
            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$";
        }

        # Pass altered request body to a backend
           location ~ \.php {
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
        }
   }
}

3.创建测试代码

nginx $> cd /var/www
nginx $> mkdir webdata
nginx $> chown www.www webdata
nginx $> vim upload.php
< ?php
  echo "REQUEST :";
  echo "Upload: " . $_REQUEST["file_name"] . "";
  echo "Type: " . $_REQUEST["file_content_type"] . "";
  echo "path: " . $_REQUEST["file_path"] . "";
  echo "MD5 " . $_REQUEST["file_md5"] . "";
  echo "Size: " . ($_REQUEST["file_size"] / 1024) . "";

  echo "_POST:";
  echo "Name : " . $_POST["file_name"] . "";
  echo "Type : " . $_POST["file_content_type"] . "";
  echo "Path : " . $_POST["file_path"] . "";
  echo "MD5  : " . $_POST["file_md5"] . "";
  echo "Size : " . ($_POST["file_size"] / 1024) .  "Kb";
?>
nginx $> vim upload.html
<html>
<body>
<h2>Select files to upload</h2>
<form name="upload" enctype="multipart/form-data" action="/upload" method="post">
<input type="file" name="file"/><br />
<input type="submit" name="submit" value="Upload"/>
<input type="hidden" name="test" value="value"/>
</form>
</body>
</html>

4.测试:  PS:不太熟悉 wordpress 下如何显示html代码·很多代码都被隐藏不显示,html 代码部分显示不全。

from:http://deidara.blog.51cto.com/400447/389873

时间: 2024-11-08 22:32:59

再次优化NGINX+php-fpm上传的相关文章

nginx安装文件上传ngx

  ngx_upload模块是nginx中一个文件上传模式了,下面我们来看看nginx安装文件上传ngx_upload模块步骤,希望例子对各位有帮助. 安装nginx,并加入nginx upload module和nginx cache purge module: mkdir ~/download cd ~/download wget http://www.grid.net.ru/nginx/download/nginx_upload_module-2.0.12.tar.gz tar zxf n

Nginx的Upload上传模块

前段时间做一个项目,需要上传文件,差不多需要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中nginx_upload_module上传模块安装配置

安装nginx_upload_module模块    代码如下 复制代码 ./configure –add-module=/usr/local/nginx_upload_module-* make make install 重启nginx即可 以下是我的nginx配置文件 前端页面提交的时候直接提交到 http://dev.local/upload 即可  代码如下 复制代码 server { listen 80; server_name test.local; index index.php

Nginx Upload Module 上传模块测试例子

传统站点在处理文件上传请求时,普遍使用后端编程语言处理,如:Java.PHP.Python.Ruby等.今天给大家介绍Nginx的一个模块,Upload Module上传模块,此模块的原理是先把用户上传的文件保存到临时文件,然后在交由后台页面处理,并且把文件的原名,上传后的名称,文件类型,文件大小set到页面. GitHub: https://github.com/vkholodkov/nginx-upload-module/tree/2.2 Site: http://wiki.nginx.or

nginx设置php上传文件大小设置

ginx php设置上传文件大小,有三个地方需要改. 1,nginx.conf client_max_body_size默认是2M的,如果通过http上传超过2M,会报413 Request Entity Too Large错误 解决办法,将client_max_body_size改大就行了. 2,php.ini upload_max_filesize = 20M     #文件上传的最大值 post_max_size = 30M   #post数据的最大值 这二个有什么区别呢,post数据,常

解决nginx+php-fpm无法上传文件问题

  解决办法 location ~ .php$ { root /var/www/html/public; client_max_body_size 50M; client_body_temp_path /tmp; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;

nginx 413:nginx,php不能上传大图问题(413)

上传图片 出现错误:413 Request Entity Too Large修改nginx.conf 在http{    client_max_body_size 10M; #添加 改大点}修改php.ini 中 upload_max_filesize = 10M post_max_size = 10M重启nginx,php-fpm 本文链接http://www.cxybl.com/html/wlbc/Php/20120627/31128.html

nginx php-fpm 上传大图片出错

1.需要安装gd库 yum -y install gd 重启动fpm 2.nginx 默认图片上传最大限制比较小. 修改PHP.ini中post_max_size upload_max_filesize max_execution_time max_input_time 打开php.ini文件,修改完毕后重启服务器.测试下上传文件....(嘻嘻,是不是传上了很大的文件?) 1.文件上传时存放文件的临时目录.必须是 PHP 进程所有者用户可写的目录.如果未指定则 PHP 使用系统默认值php.in

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 : ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module   --add-module=/data/software/lnmp1.