当前位置: 首页 > 编程日记 > 正文

tornado+nginx上传视频文件

[http://arloz.me/tornado/2014/06/27/uploadvideotornado.html]

[NGINX REFRER: Nginx upload module]

由于tornado通过表达上传的数据最大限制在100M,所以如果需要上传视屏文件的情况在需要通过其他方式实现, 此处采用nginx的nginx-upload-module和jQuery-File-Upload实现。

1.编译安装nginx-upload-module

  • 下载nginx-1.5.8
  • 下载nginx-upload-module2.0
  • 由于nginx-upload-module不支持最新版的nginx,直接编译会出错,需要打补丁 davromaniak.txt
tar xzf nginx-1.5.8
tar xzf nginx_upload_module-2.0.12.tar.gz
cd nginx_upload_moule-2.0.12
patch ngx_http_upload_module.c davromaniak.txt
cd ../nginx-1.5.8
./configure --add-module=../nginx_upload_moule-2.0.12
make & sudo make install

2.配置nginx的upload-module

upstream tornadoserver{server 127.0.0.1:8001;
}
server {
listen       8080;
server_name  localhost;
location / {proxy_pass_header Server;proxy_set_header Host $http_host;proxy_redirect off;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Scheme $scheme;proxy_pass http://tornadoserver;
}
client_max_body_size 4G;
client_body_buffer_size 1024k;if ($host !~* ^(localhost) ) {
}
location = /uploads {if ($request_method = OPTIONS) {add_header Pragma no-cache;add_header X-Content-Type-Options nosniff;# Access control for CORSadd_header Access-Control-Allow-Origin "http://localhost";add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";add_header Access-Control-Allow-Headers "cache-control, content-range, accept,\origin, session-id, content-disposition, x-requested-with, ctent-type,\content-description, referer, user-agent";add_header Access-Control-Allow-Credentials "true";# 10 minute pre-flight approvaladd_header Access-Control-Max-Age 600;return 204;}if ($request_method = POST) {add_header Pragma no-cache;add_header X-Content-Type-Options nosniff;#add_header Cache-control "no-story, no-cache, must-revalidate";# Access control for CORSadd_header Access-Control-Allow-Origin "http://localhost";add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";add_header Access-Control-Allow-Headers "cache-control, content-range, accept,\origin, session-id, content-disposition, x-requested-with,\content-type, content-description, referer, user-agent";add_header Access-Control-Allow-Credentials "true";# 10 minute pre-flight approvaladd_header Access-Control-Max-Age 600;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_pass_form_field "^X-Progress-ID$|^authenticity_token$";upload_cleanup 400 404 499 500-505;}upload_pass @fast_upload_endpoint;# {a..z} not usefull when use zsh# mkdir {1..9} {a..z} {A..Z}upload_store /tmp/uploads 1;# set permissions on the uploaded filesupload_store_access user:rw group:rw all:r;
}
location @fast_upload_endpoint {proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header Host $http_host;proxy_redirect off;proxy_pass_header 'Access-Control-Allow-Origin';proxy_pass http://tornadoserver;
}
}

3.demo页面

<!DOCTYPE HTML>
<html>
<head> <meta charset="utf-8"><title>jQuery File Upload Example</title><style>.bar {height: 18px;background: green;}
</style></head>
<body><input id="fileupload" type="file" name="files[]" data-url="uploads" multiple><script src=""></script><script src="/static/js/vendor/jquery.ui.widget.js"></script><script src="/static/js/jquery.iframe-transport.js"></script><script src="/static/js/jquery.fileupload.js"></script><script>$(function () {$('#fileupload').fileupload({dataType: 'json',done: function (e, data) {$.each(data.result.files, function (index, file) {$('<p/>').text(file.name+"  "+file.size).appendTo(document.body);});},progressall: function (e, data) {var progress = parseInt(data.loaded / data.total * 100, 10);$('#progress .bar').css( 'width', progress + '%');}});});</script><div id="progress"><div class="bar" style="width: 10%;"></div></div>
</body>
</html>

4.tornado处理

当nginx的upload-module完成视频文件的传输之后,其会设置表单数据,并转发给后台tornado服务器处理。

通过如下方式获得相关参数:

name = self.get_argument("files[].name","")
content_type = self.get_argument("files[].content_type","")
oldpath = self.get_argument("files[].path","")
size = os.path.getsize(oldpath)
files = []
files.append({"name":name,"type":content_type,"size":size})
ret = {"files":files}
self.write(tornado.escape.json_encode(ret))

5.其它配置文件参考
user root;
worker_processes 1;#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;events {
worker_connections 1024;
}http {
include mime.types;
default_type application/octet-stream;#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';#access_log logs/access.log main;sendfile on;
#tcp_nopush on;#keepalive_timeout 0;
keepalive_timeout 65;#gzip on;server {
upload_resumable on;
client_max_body_size 100m;
listen 8888;
server_name localhost;
# Upload form should be submitted to this location
location /upload {
# Pass altered request body to this location
upload_pass @test;
upload_store /tmp 1;upload_store_access user:r;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 "^submit$|^description$";
upload_cleanup 400 404 499 500-505;
}# Pass altered request body to a backend
location @test {
proxy_pass http://mongrel;
}}server{
listen 30091;
root /var/www/sms/public/video;
}upstream mongrel {
server 127.0.0.1:3001;
server 127.0.0.1:3002;
server 127.0.0.1:3003;
}server {
upload_resumable on;
client_max_body_size 100m;
listen 3000;root /var/www/sms/public;
access_log /var/www/sms/log/nginx.access.log;if (-f $document_root/system/maintenance.html) {
rewrite ^(.*)$ /system/maintenance.html last;
break;
}#upload video
location /upload_video {
# Pass altered request body to this location
upload_pass @rails;
upload_store /tmp 1;upload_store_access user:r;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 "^submit$|^description$";
upload_cleanup 400 404 499 500-505;
}# Upload image
location /upload_image {
# Pass altered request body to this location
upload_pass @rails;
upload_store /tmp 1;upload_store_access user:r;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 "^submit$|^description$";
upload_cleanup 400 404 499 500-505;
}# Pass altered request body to a backend
location @rails {
proxy_pass http://mongrel;
}location / {
proxy_set_header X-Real-IP $remote_addr;# needed for HTTPS
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_max_temp_file_size 0;if (-f $request_filename) { 
break; 
}if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}if (-f $request_filename.html) {
rewrite (.*) $1.html break;
}if (!-f $request_filename) {
proxy_pass http://mongrel;
break;
}
}error_page 500 502 503 504 /500.html;
location = /500.html {
root /var/www/sms/public;
}
}}

 
 

转载于:https://www.cnblogs.com/apexchu/p/4261324.html

相关文章:

微信小程序swiper组件宽高自适应方法

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 我把 swiper 的 width 设定成了屏幕的95%宽度, 如果想宽度也自适应的话请改成 width:{{width*2}}rpx <swiper classadvertising2 indicator-dots"true" styleheight:{{…

全面访问JavaScript的最佳资源

Looking for a new job is a daunting task. There are so many things to consider when trying to find the perfect role - location, company, job responsibilities, pay and compensation, training and much more.找一份新工作是艰巨的任务。 试图找到理想的职位时&…

Redis集群官方推荐方案 Redis-Cluster

Redis-Cluster redis使用中遇到的瓶颈 我们日常在对于redis的使用中&#xff0c;经常会遇到一些问题 1、高可用问题&#xff0c;如何保证redis的持续高可用性。 2、容量问题&#xff0c;单实例redis内存无法无限扩充&#xff0c;达到32G后就进入了64位世界&#xff0c;性能下降…

[微信小程序]单选框以及多选框实例代码附讲解

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 效果图 <radio-group class"radio-group" bindchange"radioChange"><label class"radio" wx:for"{{k7}}" wx:key"index&q…

IDL_GUI

菜单栏设计 PRO IDLGui;构建界面;显示;添加事件tlbWIDGET_BASE(xsize400,ysize400,/column,mbarmbar);实现基类fileWIDGET_BUTTON(mbar, $ &#xff1b;新建button&#xff0c;value文件)openwidget_button(file,value打开,/menu)jpgwidget_button(open,valuejpg)existwidget_…

git隐藏修改_您可能不知道的有关Git隐藏的有用技巧

git隐藏修改I have launched a newsletter Git Better to help learn new tricks and advanced topics of Git. If you are interested in getting your game better in Git, you should definitely check that out.我已经发布了Git Better通讯&#xff0c;以帮助学习Git的新技…

css 层叠式样式表(2)

一&#xff0c;样式表分类 &#xff08;1&#xff09;内联样式。 --优先级最高&#xff0c;代码重复使用最差。 &#xff08;当特殊的样式需要应用到单独某个元素时&#xff0c;可以使用。 直接在相关的标签中使用样式属性。样式属性可以包含任何 CSS 属性。&#xff09; &…

Hadoop学习笔记之三 数据流向

http://hadoop.apache.org/docs/r1.2.1/api/index.html 最基本的&#xff1a; 1. 文本文件的解析 2. 序列文件的解析 toString会将Byte数组中的内存数据 按照字节间隔以字符的形式显示出来。 文本文件多事利用已有的字符处理类&#xff0c; 序列文件多事创建byte数组&#xff0…

[微信小程序]星级评分和展示(详细注释附效果图)

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 星级评分分成两种情况: 一:展示后台给的评分数据 二:用户点击第几颗星星就显示为几星评分; <!--pages/test/test.wxml--> <view> <view>一:显示后台给的评分</…

uber_这就是我本可以免费骑Uber的方式

uberby AppSecure通过AppSecure 这就是我本可以免费骑Uber的方式 (Here’s how I could’ve ridden for free with Uber) 摘要 (Summary) This post is about a critical bug on Uber which could have been used by hackers to get unlimited free Uber rides anywhere in th…

磁盘I/O 监控 iostat

iostat -cdxm 2 5 dm-4 如果没有这个命令&#xff0c;需要安装sysstat 包。 Usage: iostat [ options ] [ <interval> [ <count> ] ]Options are:[ -c ] [ -d ] [ -N ] [ -n ] [ -h ] [ -k | -m ] [ -t ] [ -V ] [ -x ] [ -z ][ <device> [...] | ALL ] [ -p…

[微信小程序]物流信息样式加动画效果(源代码附效果图)

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 效果图片:(信息仅为示例) <!--pages/order/order_wl.wxml--> <view classpage_row top><image classgoods src../../images/dsh.png></image><view cl…

在 Ubuntu 14.04 Chrome中安装Flash Player(转)

在 Ubuntu 14.04 中安装 Pepper Flash Player For Chromium 一个 Pepper Flash Player For Chromium 的安装器已经被 Ubuntu14.04 的官方源收录。Flash Player For Linux 自11.2 起已经停止更新&#xff0c;目前 Linux 平台下面的 Flash Player 只能依靠 Google Chrom 的 PPAPI…

数据结构显示树的所有结点_您需要了解的有关树数据结构的所有信息

数据结构显示树的所有结点When you first learn to code, it’s common to learn arrays as the “main data structure.”第一次学习编码时&#xff0c;通常将数组学习为“主要数据结构”。 Eventually, you will learn about hash tables too. If you are pursuing a Comput…

Unity应用架构设计(9)——构建统一的 Repository

谈到 『Repository』 仓储模式&#xff0c;第一映像就是封装了对数据的访问和持久化。Repository 模式的理念核心是定义了一个规范&#xff0c;即接口『Interface』&#xff0c;在这个规范里面定义了访问以及持久化数据的行为。开发者只要对接口进行特定的实现就可以满足对不同…

PHP连接数据库并创建一个表

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 <html> <body><form action"test.class.php" method"post"> title: <input type"text" name"title"><br> centent: <input t…

MyBatis 入门

什么是 MyBatis &#xff1f; MyBatis 是支持定制化 SQL、存储过程以及高级映射的优秀的持久层框架。MyBatis 避免了几乎所有的 JDBC 代码和手工设置参数以及抽取结果集。MyBatis 使用简单的 XML 或注解来配置和映射基本体&#xff0c;将接口和 Java 的 POJOs(Plain Old Java O…

cms基于nodejs_我如何使基于CMS的网站脱机工作

cms基于nodejsInterested in learning JavaScript? Get my ebook at jshandbook.com有兴趣学习JavaScript吗&#xff1f; 在jshandbook.com上获取我的电子书 This case study explains how I added the capability of working offline to the writesoftware.org website (whic…

how-to-cartoon-ify-an-image-programmatically

http://stackoverflow.com/questions/1357403/how-to-cartoon-ify-an-image-programmatically 转载于:https://www.cnblogs.com/guochen/p/6655333.html

Android Studio 快捷键

2015.02.05补充代码重构快捷键 Alt回车 导入包 自动修正CtrlN 查找类​CtrlShiftN 查找文件CtrlAltL 格式化代码CtrlAltO 优化导入的类和包AltInsert 生成代码(如get,set方法,构造函数等)CtrlE或者AltShiftC 最近更改的代码CtrlR 替换文本CtrlF 查找文本CtrlShiftSpace 自动补全…

【微信小程序】异步请求,权重,自适应宽度并折行,颜色渐变,绝对定位

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 写这篇博文主要是为了能够给到大家做类似功能一些启迪&#xff0c;下面效果图中就是代码实现的效果&#xff0c;其中用到的技巧点还是比较多的&#xff0c; <!--pages/demo_list/d…

服务器部署基础知识_我在生产部署期间学到的知识

服务器部署基础知识by Shruti Tanwar通过Shruti Tanwar 我在生产部署期间学到的知识 (What I learned during production deployment) Production deployment. The final stage of every project. When all the hard work you’ve put in over the course of time goes live t…

STM32 KEIL中 负数绝对值处理

使用数码管显示负温度时需要把负数转换为绝对值 #include<math.h> 使用abs 或者自己写函数 #define ABS(x) ((x)>0?(x):-(x)))转载于:https://www.cnblogs.com/yekongdexingxing/p/6657371.html

js数组按照下标对象的属性排序

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 根据数组中某个参数的值的大小进行升序 <script type"text/javascript">function compare(val) {return function (a, b) {var value1 a[val];var value2 b[val];return value1…

window 下相关命令

1. 启动window服务(各种应用启动设置的地方)命令方式&#xff1a; 1). window 按钮(输入CMD的地方)处输入&#xff1a;services.msc &#xff0c;然后执行。 // 输入命令正确&#xff0c;上面的待选框中会出现要执行的命令。msc 可以理解为Microsoft client 2). 计算机 -- …

javascript语法糖_语法糖和JavaScript糖尿病

javascript语法糖by Ryan Yurkanin瑞安尤卡宁(Ryan Yurkanin) 语法糖和JavaScript糖尿病 (Syntactic Sugar and JavaScript Diabetes) Syntactic sugar is shorthand for communicating a larger thought in a programming language.语法糖是用编程语言传达更大思想的简写。 …

《DSP using MATLAB》示例Example7.23

代码&#xff1a; wp 0.2*pi; ws 0.3*pi; Rp 0.25; As 50; [delta1, delta2] db2delta(Rp, As);[N, f, m, weights] firpmord([wp, ws]/pi, [1, 0], [delta1, delta2]);N f m weightsh firpm(N, f, m, weights); [db, mag, pha, grd, w] freqz_m(h, [1]);delta_w 2*pi…

css画图笔记

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 正文&#xff1a; 在网页中&#xff0c;经常会用到各种Icon&#xff0c;如果老是麻烦设计狮画出来不免有些不好意思&#xff0c;所以有时候我们也可以用CSS写出各种简单的形状&#xff0c;一来可以减轻…

Web前端开发最佳实践(8):还没有给CSS样式排序?其实你可以更专业一些

前言 CSS样式排序是指按照一定的规则排列CSS样式属性的定义&#xff0c;排序并不会影响CSS样式的功能和性能&#xff0c;只是让代码看起来更加整洁。CSS代码的逻辑性并不强&#xff0c;一般的开发者写CSS样式也很随意&#xff0c;所以如果不借助工具&#xff0c;不太容易按照既…

超越Android:Kotlin在后端的工作方式

by Adam Arold亚当阿罗德(Adam Arold) 超越Android&#xff1a;Kotlin在后端的工作方式 (Going Beyond Android: how Kotlin works on the Backend) This article is part of a series.本文是系列文章的一部分。 While most developers use Kotlin on Android, it is also a …