Fastdfs supports dynamic thumbnails
One, source Pack preparation:
graphicsmagick-1.3.20.tar.gz
jpegsrc.v9a.tar.gz
lua-5.3.0.tar.gz
Lua jit-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
Install system dependent packages
Yum install Libtermcap-devel Ncurses-devel libevent-devel readline-devel pcre-*
Install lua-5.3.0
TAR-XZVF lua-5.3.0.tar.gz
CD lua-5.3.0/
make Linux
make install
Install LuaJIT-2.0.2:
TAR-ZXVF luajit-2.0.2.tar.gz
CD LuaJIT-2.0.2
make
make install
Install jpegsrc.v9a. tar.gz
TAR-XZVF graphicsmagick-1.3.20.tar.gz
CD graphicsmagick-1.3.20/
./configure
Make
Make INS Tall
Install lua-nginx-module-0.9.16
TAR-XZVF lua-nginx-module-0.9.16.tar.gz
Install ngx_devel_kit0.2.19:
Tar-x ZVF ngx_devel_kit0.2.19.tar.gz
Establish soft links
Ln-sv/usr/local/lib/libjpeg.so.9/lib64/libjpeg.so.9
Ln-sv/usr/loc Al/lib/libluajit-5.1.so/lib64/liblua-5.1.so.2
Chmod-r 777/mnt/fastdfs_storage_data/permissions required to access a picture
Copy Fastdfs.lua and Restyfastdfs.lua to/etc/fdfs
which modifies Fastdfs.lua
Fdfs:set_tracker ("192.168.65.133", 22122)
Modify the Nginx profile properties:
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 _r
oot/$3/$4/";
Set $image _name "$";
Set $file "$image _dir$image_name";
} if (!-f $file) {# Closes the LUA code cache, facilitates debugging the Lua script Lua_code_cache off; Content_by_lua_file "/etc/fdfs/fastdfs.lua";
} Ngx_fastdfs_module;
} error_page 502 503 504/50x.html;
Location =/50x.html {root html; }
}
}
Recompile Nginx
Mkdir/etc/nginx
cd 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
install
service nginx restart
Fastdfs.lua script content: Because there are too many Restyfastdfs.lua script content. can be downloaded.
Local function WriteFile (filename, info) local wfile=io.open (filename, "w")--Write to file (W overwrite) assert (Wfile)--Verify error on open Wfile:write (Info)--Write incoming content wfile:close ()--remember to close the end after the call--detection path is directory local function is_dir (spath) I F Type (spath) ~= "string" then return False end local response = Os.execute ("CD" ... spath) If response = = 0 Then return True end return False end--detects whether the file exists a local file_exists = Functi On (name) local F=io.open (name, "R") if F~=nil then Io.close (f) return true else return False end
Nil local 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 file if not file_exists (originalfile) then local Filei
D = 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) fdfs:set_storage_keepalive (0) 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) end--Create thumbnails 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 ' return false ' if Table.contains (image_sizes, area) then local Co Mmand = "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