fastdfs支持缩略图
来源:互联网 发布:linux sort 小数 编辑:程序博客网 时间:2024/05/29 19:10
fastdfs支持动态缩略图
一, 源码包准备:
GraphicsMagick-1.3.20.tar.gz
jpegsrc.v9a.tar.gz
lua-5.3.0.tar.gz
LuaJIT-2.0.2.tar.gz
lua-nginx-module-0.9.14.tar.gz
ngx_devel_kit0.2.19.tar.gz
git clone https://github.com/agentzh/echo-nginx-module
restyfastdfs.lua http://download.csdn.net/detail/dwl764457208/9216459
fastdfs.lua http://download.csdn.net/detail/dwl764457208/9216463
安装系统的相关依赖包
yum install libtermcap-devel ncurses-devel libevent-devel readline-devel pcre-*
安装lua-5.3.0
tar -xzvf lua-5.3.0.tar.gz
cd lua-5.3.0/
make linux
make install
安装LuaJIT-2.0.2:
tar -zxvf LuaJIT-2.0.2.tar.gz
cd LuaJIT-2.0.2
make
make install
安装jpegsrc.v9a.tar.gz
tar -xzvf GraphicsMagick-1.3.20.tar.gz
cd GraphicsMagick-1.3.20/
./configure
make
make install
安装lua-nginx-module-0.9.16
tar -xzvf lua-nginx-module-0.9.16.tar.gz
安装ngx_devel_kit0.2.19:
tar -xzvf ngx_devel_kit0.2.19.tar.gz
建立软链接
ln -sv /usr/local/lib/libjpeg.so.9 /lib64/libjpeg.so.9
ln -sv /usr/local/lib/libluajit-5.1.so /lib64/liblua-5.1.so.2
chmod -R 777 /mnt/fastdfs_storage_data/ 访问图片需要的权限
将fastdfs.lua和restyfastdfs.lua拷贝至/etc/fdfs
其中修改fastdfs.lua
fdfs:set_tracker(“192.168.65.133”,22122)
修改一下nginx配置文件属性:
vi /etc/nginx/nginx.conf
worker_processes 4;events { worker_connections 10240;}http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; lua_package_path "/etc/fdfs/?.lua;;"; server { listen 80; server_name localhost; location / { root html; index index.html index.htm; default_type text/html; content_by_lua 'ngx.say("<p>hello,world</p>")'; } location /group1/M00 { alias /mnt/fastdfs_storage_data; set $image_root "/mnt/fastdfs_storage_data/data"; if ($uri ~ "/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/(.*)") { set $image_dir "$image_root/$3/$4/"; set $image_name "$5"; set $file "$image_dir$image_name"; } if (!-f $file) { # 关闭lua代码缓存,方便调试lua脚本 lua_code_cache off; content_by_lua_file "/etc/fdfs/fastdfs.lua"; } ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }}
重新编译nginx
mkdir /etc/nginxcd nginx-1.9.6./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin --conf-path=/etc/nginx/nginx.conf --with-pcre --add-module=/usr/local/ngx_devel_kit-0.2.19--add-module=/usr/local/lua-nginx-module-0.9.16 --add-module=/usr/local/echo-nginx-module/echo-nginx-module --add-module=/usr/local/fastdfs-nginx-module/src --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module make make installservice nginx restart
fastdfs.lua脚本内容:由于restyfastdfs.lua脚本内容太多。可以下载。
local function writefile(filename, info) local wfile=io.open(filename, "w") --写入文件(w覆盖) assert(wfile) --打开时验证是否出错 wfile:write(info) --写入传入的内容 wfile:close() --调用结束后记得关闭end-- 检测路径是否目录local function is_dir(sPath) if type(sPath) ~= "string" then return false end local response = os.execute( "cd " .. sPath ) if response == 0 then return true end return falseend-- 检测文件是否存在local file_exists = function(name) local f=io.open(name,"r") if f~=nil then io.close(f) return true else return false endendlocal area = nillocal originalUri = ngx.var.uri;local originalFile = ngx.var.file;local index = string.find(ngx.var.uri, "([0-9]+)x([0-9]+)"); if index then originalUri = string.sub(ngx.var.uri, 0, index-2); area = string.sub(ngx.var.uri, index); index = string.find(area, "([.])"); area = string.sub(area, 0, index-1); local index = string.find(originalFile, "([0-9]+)x([0-9]+)"); originalFile = string.sub(originalFile, 0, index-2)end-- check original fileif not file_exists(originalFile) then local fileid = string.sub(originalUri, 2); -- main local fastdfs = require('restyfastdfs') local fdfs = fastdfs:new() fdfs:set_tracker("192.168.65.113", 22122) fdfs:set_timeout(1000) fdfs:set_tracker_keepalive(0, 100) fdfs:set_storage_keepalive(0, 100) local data = fdfs:do_download(fileid) if data then -- check image dir if not is_dir(ngx.var.image_dir) then os.execute("mkdir -p " .. ngx.var.image_dir) end writefile(originalFile, data) endend-- 创建缩略图local image_sizes = {"80x80", "800x600", "40x40", "60x60"}; function table.contains(table, element) for _, value in pairs(table) do if value == element then return true end end return false end if table.contains(image_sizes, area) then local command = "gm convert " .. originalFile .. " -resize " .. area .. " " .. ngx.var.file; os.execute(command); end;if file_exists(ngx.var.file) then --ngx.req.set_uri(ngx.var.uri, true); ngx.exec(ngx.var.uri)else ngx.exit(404)end
- fastdfs支持缩略图
- fastdfs 缩略图
- nginx lua fastdfs动态缩略图
- fastdfs支持断点上传
- FastDFS的PHP支持
- nginx-lua-fastdfs-GraphicsMagick 动态生成缩略图
- nginx缩略图image_filter配置整合fastdfs
- 给FastDFS安装nginx支持
- FastDFS图片服务器搭建-支持分布式
- fastdfs连接池,支持spring,防盗链
- fastdfs
- fastdfs
- FastDFS
- FastDFS
- fastdfs
- FastDFS
- fastdfs
- FastDFS
- Wince在进程控制程序里的解决办法 error LNK2019错误解决办法
- 用PHP的imagettftext绘制图片的换行问题。
- Lua中的基本函数库
- 【图像处理】人脸预处理工具FaceTools
- viewpager无限循环滑动两张白屏问题的笨解决办法
- fastdfs支持缩略图
- 3.2 Stack min
- Oracle视图概念与语法
- XCode 7.1 发送HTTP请求报错解决办法
- Couchbase学习笔记(1)——概述
- Windows下利用CMake和VS2013编译OpenCV
- asp_net_webapi_httpclient.html
- 九度OJ 1205:N阶楼梯上楼问题 (斐波那契数列)
- matlab中的containers.Map()