欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Fastdfs與nginx進(jìn)行壓縮圖片比率

 更新時(shí)間:2014年07月15日 09:36:47   投稿:hebedich  
前陣子,工作搞了一下Fastdfs與nginx進(jìn)行壓縮圖片比率存儲(chǔ)在服務(wù)器中,今天應(yīng)用下工作時(shí)間記錄下.

在此先把前面自己做的那個(gè)功能在此分享下,是一個(gè)模仿淘寶的,希望大神們有什么想法可以不吝賜教:

自己是通過前面的參考配置lua與nginx的結(jié)合使用,利用腳本語言lua的強(qiáng)大特性和nginx的特性來實(shí)現(xiàn)這個(gè)功能,在nginx.conf的配置文件中加入如下代碼:

server {

  listen  22222;

  server_name localhost;

  # server_name somename alias another.alias;

  location /images/{

  alias /root/images;

  set $image_root /root;

  set $file $image_root$uri;

  content_by_lua '

    ngx.header.content_type = "text/plain";

    ngx.say(ngx.var.file);

   ';

  }

  location /lua{

   set $test "hello, world.";

   content_by_lua '

     ngx.header.content_type = "text/plain";

     ngx.say(ngx.var.test);

   ';

  }

  location /group1/M00 {

   alias /usr/local/servers/data/fdfs/data;

   set $image_root "/usr/local/servers/data/fdfs/data";

   # alias /root/images;

   # set $image_root "/root/images";

   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";

    }

  # content_by_lua '

   #  ngx.header.content_type = "text/plain";

   #  ngx.say(ngx.var.image_dir);

   #  ngx.say(ngx.var.image_name);

   #  ngx.say(ngx.var.file);

   # ';

    if ( !-f $file ) {

    # 關(guān)閉lua代碼緩存,方便調(diào)試lua腳本

    #lua_code_cache off;

    content_by_lua_file "/usr/local/servers/lua/convert.lua";

    }

     ngx_fastdfs_module;

  }

  # location ~ /group[1-3]/M00{

   # root /usr/local/servers/data/fdfs/data; #/fdfs/storage/data;

   # ngx_fastdfs_module;

   # }

  }

這里面利用了nginx的正則表達(dá)式,正則表達(dá)式是相當(dāng)強(qiáng)悍的,可以得到你需要訪問的uri的值。

然后再convert.lua中寫入如下代碼:

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);

 index1 = string.find(area, "([.])");

 area1 = string.sub(area, 0, index1-1);

 local index2 = string.find(originalFile, "([0-9]+)x([0-9]+)");

 originalFile1 = string.sub(originalFile, 0, index2-2)

end

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, area1) then

 local command = "/usr/bin/gm convert " .. originalFile1 .. " -thumbnail " .. area1 .. " -background gray -gravity center -extent " .. area1 .. " " .. ngx.var.file;

 os.execute(command);

end;

~差不多這樣就可以實(shí)現(xiàn)功能了,通過訪問可以實(shí)現(xiàn)比率壓縮,因?yàn)樵谏习鄷r(shí)間暫時(shí)就這么寫下了,目前的一個(gè)工作還有很多功能需要實(shí)現(xiàn),如有看不懂的可以留言,大神們可以指教,謝謝!

      參考:http://www.v2ex.com/t/113845

       http://blog.sina.com.cn/openresty

       http://write.blog.csdn.net/postedit

        https://github.com/azurewang/lua-resty-fastdfs/blob/master/lib/resty/fastdfs/storage.lua

http://www.dbjr.com.cn/sys/CentOS/55070.htm

http://wiki.nginx.org/HttpLuaModule

相關(guān)文章

  • k8s部署nginx訪問Tomcat的實(shí)現(xiàn)示例

    k8s部署nginx訪問Tomcat的實(shí)現(xiàn)示例

    本文介紹了如何使用Kubernetes部署Nginx,并通過Nginx訪問Tomcat,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-08-08
  • 詳解Nginx location 匹配規(guī)則

    詳解Nginx location 匹配規(guī)則

    本篇文章主要介紹了Nginx location 匹配規(guī)則,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-05-05
  • iis+nginx實(shí)現(xiàn)負(fù)載均衡的詳細(xì)步驟

    iis+nginx實(shí)現(xiàn)負(fù)載均衡的詳細(xì)步驟

    這篇文章主要為大家詳細(xì)介紹了iis+nginx實(shí)現(xiàn)負(fù)載均衡的詳細(xì)步驟 ,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Nginx服務(wù)器進(jìn)程數(shù)設(shè)置和利用多核CPU的方法

    Nginx服務(wù)器進(jìn)程數(shù)設(shè)置和利用多核CPU的方法

    這篇文章主要介紹了Nginx服務(wù)器進(jìn)程數(shù)設(shè)置和利用多核CPU的方法,這樣便可以更大限度地提高Nginx運(yùn)行效率,需要的朋友可以參考下
    2015-08-08
  • Nginx中配置用戶服務(wù)器訪問認(rèn)證的方法示例

    Nginx中配置用戶服務(wù)器訪問認(rèn)證的方法示例

    這篇文章主要介紹了Nginx中配置用戶服務(wù)器訪問認(rèn)證的方法示例,包括一個(gè)用perl腳本來實(shí)現(xiàn)的方法,需要的朋友可以參考下
    2016-01-01
  • Nginx配置同一個(gè)域名同時(shí)支持http與https兩種方式訪問實(shí)現(xiàn)

    Nginx配置同一個(gè)域名同時(shí)支持http與https兩種方式訪問實(shí)現(xiàn)

    這篇文章主要介紹了Nginx配置同一個(gè)域名同時(shí)支持http與https兩種方式訪問實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • nginx找到默認(rèn)根目錄(root?html)的方法

    nginx找到默認(rèn)根目錄(root?html)的方法

    這篇文章主要給大家介紹了nginx如何找到默認(rèn)根目錄(root?html),文中給出詳細(xì)的解決方法,通過代碼示例講解的非常詳細(xì),具有一定的參考價(jià)值,需要的朋友可以參考下
    2023-11-11
  • Nginx報(bào)錯(cuò)104:Connection?reset?by?peer問題的解決及分析

    Nginx報(bào)錯(cuò)104:Connection?reset?by?peer問題的解決及分析

    最近恰好又遇到這了個(gè)錯(cuò)誤,為了加深記憶,所以記錄下我遇到這個(gè)錯(cuò)誤的主要原因,下面這篇文章主要給大家介紹了關(guān)于Nginx報(bào)錯(cuò)104:Connection?reset?by?peer問題的解決及分析的相關(guān)資料,需要的朋友可以參考下
    2022-07-07
  • nginx中共享內(nèi)存的使用詳解

    nginx中共享內(nèi)存的使用詳解

    這篇文章主要介紹了nginx中共享內(nèi)存的使用詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-06-06
  • 關(guān)于nginx沒有跳轉(zhuǎn)到upstream地址的解決

    關(guān)于nginx沒有跳轉(zhuǎn)到upstream地址的解決

    這篇文章主要介紹了關(guān)于nginx沒有跳轉(zhuǎn)到upstream地址的解決,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09

最新評(píng)論