再次优化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
再次优化NGINX+php-fpm上传的更多相关文章
- Nginx的Upload上传模块
前段时间做一个项目,需要上传文件,差不多需要20M左右,普通用php处理会比较麻烦,经常超时,而且大量占用资源.于是搜索了下,决定用nginx的upload上传模块来处理. 你可以在这里:http:/ ...
- h5 + nginx + php 视频上传之突破文件大小受限的解决办法
一.环境: CentOS 6.8 nginx 1.8.0 php 7.0.10 二.背景 基于 nginx + php 的 h5 项目,上传视频的时候,如果视频太大,会上传失败. 三.正文 一份视频传 ...
- Nginx反向代理上传大文件报错(failed to load resource : net :: ERR_CONNECTION_RESET)
转自: https://blog.csdn.net/kinginblue/article/details/50753271?locationNum=14&fps=1 Nginx反向代理上传大文 ...
- nginx代理图片上传以及访问
nginx代理图片上传 首先需要利用nginx代理图片访问参考 https://www.cnblogs.com/TJ21/p/12609017.html 编写接受文件的controller @Post ...
- nginx实现文件上传和下载
nginx实现文件上传和下载 发布时间:2020-06-05 16:45:27 来源:亿速云 阅读:156 作者:Leah 栏目:系统运维 这篇文章给大家分享的是nginx实现文件上传和下载的方法.小 ...
- nginx代理图片上传以及访问 nginx 图片上传完整版
nginx代理图片上传 首先需要利用nginx代理图片访问参考 https://www.cnblogs.com/TJ21/p/12609017.html 编写接受文件的controller 1 @Po ...
- 分布式文件系统 - FastDFS 配置 Nginx 模块及上传测试
也不说废话,直接干 上一篇 分布式文件系统 - FastDFS 在 CentOS 下配置安装部署 中安装了 FastDFS 后,并配置启动了 Tracker 和 Storage 服务,已经可以上传文件 ...
- [svc]nginx限制客户端上传附件的大小
300 行 python 代码的轻量级 HTTPServer 实现文件上传下载 系统环境 [root@n1 conf]# cat /etc/redhat-release CentOS Linux re ...
- 让nginx支持文件上传的几种模式
文件上传的几种不同语言和不同方法的总结. 第一种模式 : PHP 语言来处理 这个模式比较简单, 用的人也是最多的, 类似的还有用 .net 来实现, jsp来实现, 都是处理表单.只有语言的差别, ...
随机推荐
- maven Spring MVC项目
IntelliJ IDEA上创建maven Spring MVC项目 各软件版本 利用maven骨架建立一个webapp 建立相应的目录 配置Maven和SpringMVC 配置Maven的pom.x ...
- 《编程珠玑》第二章 aha算法
A题:给定一个最多包含40亿个随机排列的32位整数的顺序文件,找出一个不在文件中的32位整数. 1.在文件中至少存在这样一个数? 2.如果有足够的内存,如何处理? 3.如果内存不足,仅可以用文件来进行 ...
- c++ ifstream ofstream 文件流
#include <fstream>ofstream //文件写操作 内存写入存储设备 ifstream //文件读操作,存储设备读区到内存中fstream //读写操作,对打开的文件可进 ...
- c3p0链接池
频繁的链接数据库是非常消耗性能的,所以就采用了将一定量的链接保存在一个池中,这个池我们叫做链接池. 详细请看:http://baike.baidu.com/link?url=dlTW-fTS3N_-j ...
- UESTC_我要长高 CDOJ 594
韩父有N个儿子,分别是韩一,韩二…韩N.由于韩家演技功底深厚,加上他们间的密切配合,演出获得了巨大成功,票房甚至高达2000万.舟子是名很有威望的公知,可是他表面上两袖清风实则内心阴暗,看到韩家红红火 ...
- Letter Combinations of a Phone Number 解答
Question Given a digit string, return all possible letter combinations that the number could represe ...
- POJ3268 Silver Cow Party(dijkstra+矩阵转置)
Silver Cow Party Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 15156 Accepted: 6843 ...
- Python re模块 正则表达式
1 简介 就其本质而言,正则表达式(或 RE)是一种小型的.高度专业化的编程语言,(在Python中)它内嵌在Python中,并通过 re 模块实现.正则表达式模式被编译成一系列的字节码,然后由用 C ...
- iOS学习之iOS沙盒(sandbox)机制和文件操作(一)
1.iOS沙盒机制 iOS应用程序仅仅能在为该改程序创建的文件系统中读取文件,不能够去其他地方訪问,此区域被成为沙盒,所以全部的非代码文件都要保存在此,比如图像,图标,声音,映像,属性列表,文本文件等 ...
- 树的直径 poj 2631
树的直径:从随意一点出发,BFS找到最远的距离,然后在从该点出发BFS找到最远的距离 #include <iostream> #include <algorithm> #inc ...