-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
901 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
server { | ||
listen 999; | ||
server_name 10.4.81.71; | ||
#lua_code_cache off; | ||
|
||
location / { | ||
root html; | ||
index index.html index.htm; | ||
} | ||
|
||
location /group1 { | ||
#root /data1/fdfs_tracker/data/; | ||
#ngx_fastdfs_module; | ||
alias /data1/group1; | ||
|
||
set $image_root "/data1/group1"; | ||
if ($uri ~ "/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/(.*)") { | ||
set $image_dir "$image_root/$2/$3/$4/"; | ||
set $image_name "$5"; | ||
set $file "$image_dir$image_name"; | ||
} | ||
|
||
if (!-f $file) { | ||
content_by_lua_file "/usr/local/nginx2/conf/lua/fastdfs.lua"; | ||
} | ||
#curl "http://10.4.27.59:777/group1/M00/00/00/CgQbTlaoVpGAKLG7AAAqejxSlcQ450.jpg?attname=filename.jpgg" -I | ||
#curl "http://10.4.27.59:777/group1/M00/00/00/CgQbTlaoVpGAKLG7AAAqejxSlcQ450.jpg?attname=filename.jpg" -I | ||
if ($arg_attname ~ "^(.*).jpg$") { | ||
add_header Content-Disposition "attachment;filename=$arg_attname"; | ||
} | ||
} | ||
location /group2 { | ||
#root /data1/fdfs_tracker/data/; | ||
#ngx_fastdfs_module; | ||
alias /data1/group2; | ||
|
||
set $image_root "/data1/group2"; | ||
if ($uri ~ "/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/([a-zA-Z0-9]+)/(.*)") { | ||
set $image_dir "$image_root/$2/$3/$4/"; | ||
set $image_name "$5"; | ||
set $file "$image_dir$image_name"; | ||
} | ||
|
||
if (!-f $file) { | ||
content_by_lua_file "/usr/local/nginx2/conf/lua/fastdfs.lua"; | ||
} | ||
if ($arg_attname ~ "^(.*).jpg$") { | ||
add_header Content-Disposition "attachment;filename=$arg_attname"; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
server { | ||
listen 999; | ||
server_name localhost; | ||
|
||
location /status1 { | ||
stub_status on; | ||
access_log off; | ||
allow 10.0.0.0/8; | ||
deny all; | ||
} | ||
location /status2 { | ||
check_status; | ||
access_log off; | ||
allow 10.0.0.0/8; | ||
deny all; | ||
} | ||
|
||
error_page 500 502 503 504 /50x.html; | ||
location = /50x.html { | ||
root html; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
-- 写入文件 | ||
|
||
-- ngx.log(ngx.ERR,"aaaaaaaaaaaaaaaaa",ngx.var.file) | ||
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 ) | ||
local response = os.execute( "test -d " .. sPath ) | ||
if response == 0 then | ||
return true | ||
end | ||
return false | ||
end | ||
|
||
-- 检测文件是否存在 | ||
local file_exists = function(name) | ||
local f=io.open(name,"r") | ||
if f~=nil then io.close(f) return true else return false end | ||
end | ||
|
||
local area = 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 fileid = string.sub(originalUri, 2); | ||
-- main | ||
local bit = require('bit') | ||
local fastdfs = require('restyfastdfs') | ||
local fdfs = fastdfs:new() | ||
fdfs:set_timeout(1000) | ||
fdfs:set_tracker_keepalive(0, 100) | ||
fdfs:set_storage_keepalive(0, 100) | ||
|
||
local tracker_list = {"10.4.81.71","10.4.81.72"} | ||
for NUMBER,IP in pairs(tracker_list) do | ||
fdfs:set_tracker(IP, 22122) | ||
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) | ||
ngx.log(ngx.DEBUG,"tracker connect:",IP) | ||
break | ||
end | ||
ngx.log(ngx.ERR,"tracker not connect:",IP) | ||
if NUMBER == table.getn(tracker_list) then | ||
ngx.exit(502) | ||
end | ||
end | ||
end | ||
|
||
-- 创建缩略图 | ||
local image_sizes = {"80x80", "800x600", "40x40", "60x60", "1000x1000"}; | ||
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 .. " -thumbnail " .. area .. " -background gray -gravity center -extent " .. 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 |
Oops, something went wrong.