博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
再次优化NGINX+php-fpm上传
阅读量:6232 次
发布时间:2019-06-21

本文共 3588 字,大约阅读时间需要 11 分钟。

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

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

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

For  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.gznginx $> tar zxvf nginx_upload_module-2.0.12.tar.gznginx $> 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.12nginx $> makenginx $> make install

2.创建配置文件:

nginx $> cd /usr/local/nginx/conf
nginx $> vim nginx.confuser    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/wwwnginx $> mkdir webdatanginx $> 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

Select files to upload

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

本文转自Deidara 51CTO博客,原文链接:http://blog.51cto.com/deidara/389873,如需转载请自行联系原作者

你可能感兴趣的文章
p4570 [BJWC2011]元素
查看>>
基础数据结构-线性表-顺序表的合并操作
查看>>
MFC 程序入口和执行流程
查看>>
Spring+SpringMVC+MyBatis深入学习及搭建(五)——动态sql
查看>>
【7】异常处理
查看>>
201621123057 《Java程序设计》第9周学习总结
查看>>
题目1081:递推数列 (矩阵快速幂解递推式)
查看>>
【转】 FRTO—虚假超时剖析
查看>>
html区块元素
查看>>
json数据结构
查看>>
使用classList来实现两个按钮样式的切换
查看>>
二分匹配 飞行员配对方案问题
查看>>
几个著名java开源缓存框架的介绍
查看>>
CSS核心内容:层叠和继承
查看>>
windwos phone 的listbox 的各种细节
查看>>
Resin
查看>>
理解Android虚拟机体系结构(转)
查看>>
Redis系列之(一):10分钟玩转Redis(转)
查看>>
调试逆向分为动态分析技术和静态分析技术(转)
查看>>
上传文件的大小限制 专题
查看>>