• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 224  文章 - 41  trackbacks - 0
            <2010年9月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            享受編程

            常用鏈接

            留言簿(11)

            隨筆分類(159)

            隨筆檔案(224)

            文章分類(2)

            文章檔案(4)

            經典c++博客

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            OpenResty 它打包了標準的 Nginx 核心,很多的常用的第三方模塊,以及它們的大多數依賴項。

            如果需要nginx的第三方庫的時候,可以考慮OpenResty,可以少掉很多安裝的麻煩,OpenResty基本上安裝了常用的nginx第三方庫。

            OpenResty的安裝:

            安裝nginx 中 rewrite模塊等需要的插件:

            apt-get install libreadline-dev libpcre3-dev libssl-dev perl build-essential
            下載最新版的OpenResty
            http://openresty.org/
            wget http://openresty.org/download/ngx_openresty-1.2.7.1.tar.gz
            tar -xvf nngx_openresty-1.2.7.1.tar.gz
            mv nngx_openresty-1.2.7.1 /usr/local/openresty-1.2.7.1
            cd openresty-1.2.7.1
            ./configure --with-luajit --prefix=/usr/local/openresty
            make & make install

            這樣基本就可以把nginx基本的第三方庫安裝進去

            在/to/nginx/conf 下修改配置文件nginx.config

            location /hello {
                  default_type 'text/plain';
                  content_by_lua 'ngx.say("hello, lua")';
            }

            /to/nginx/sbin/nginx   #啟動nginx

            或者/to/nginx/sbin/nginx –s reload #重啟nginx
            訪問localhost/hello
            會出現“hello,lua”

            讓nginx 中的nginx_lua_module支持mysql 和memcache
            下載
            https://github.com/agentzh/lua-resty-memcached
            https://github.com/agentzh/lua-resty-mysql

            對于訪問接口的統一有很多的處理方式,這里介紹使用nginx lua 訪問mysql并用memcache緩存起來。

             

            location /getXxxInfo {
                        default_type 
            'text/plain';
                        content_by_lua 
            '
               
                   
            --先從memcache提取數據

                            local args 
            = ngx.req.get_uri_args()
                
                
            if args["appleid"== nil then
                    
            return
                end
                
                local memcached 
            = require "resty.memcached"
                            local memc, err 
            = memcached:new()
                            
            if not memc then
                                ngx.say(
            "failed to instantiate memc: ", err)
                                
            return
                            end


                            memc:set_timeout(
            1000-- 1 sec
                
                local ok, err 
            = memc:connect("192.168.40.xxx"11211)
                            
            if not ok then
                                ngx.say(
            "failed to connect: ", err)
                                
            return
                            end

                            local res, flags, err 
            = memc:get(args["appleid"] )
                            if err then
                                ngx.say(
            "failed to get dog: ", err)
                                
            return
                            end
                
                
            --數據不在memcache中 從數據庫提取并放到memcache
                
            if not res then

                 local mysql 
            = require "resty.mysql"
                 local db, err 
            = mysql:new()
                 
            if not db then
                  ngx.say(
            "failed to instantiate mysql: ", err)
                  
            return
                 end

                 db:set_timeout(
            1000-- 1 sec

                 local ok, err, errno, sqlstate 
            = db:connect{
                  host 
            = "xxx.xxx.xx.xxx",
                  port 
            = 3306,
                  database 
            = "xxxx",
                  user 
            = "root",
                  password 
            = "xxxx",
                  max_packet_size 
            = 1024 * 1024 
                 }
               
                 
            if not ok then
                  ngx.say(
            "failed to connect: ", err, "", errno, " ", sqlstate)
                  
            return
                 end

                 
            --ngx.say("connected to mysql.")
                 
                 sql 
            = "select * from xxx where xxx = "..args["xxx"]

                 res, err, errno, sqlstate 
            =
                  db:query(sql)
                 
            if not res then
                  ngx.say(
            "bad result: ", err, "", errno, "", sqlstate, ".")
                  
            return
                 end

                 local cjson 
            = require "cjson"
                 ngx.say(cjson.encode(res))
                 
                 local ok, err 
            = memc:set(args["xxxx"], cjson.encode(res))
                 
            if not ok then
                  ngx.say(
            "failed to set dog: ", err)
                  
            return
                 end

                 local ok, err 
            = db:set_keepalive(0100)
                 
            if not ok then
                  ngx.say(
            "failed to set keepalive: ", err)
                  
            return
                 end
                                
            return
                            end

                            ngx.say(res)

                            memc:set_keepalive(
            0100)
                
                            
            ';
                    }


             

            posted on 2013-03-21 16:53 漂漂 閱讀(17533) 評論(0)  編輯 收藏 引用
            国产ww久久久久久久久久| 国产精品成人久久久| 久久美女网站免费| 伊人久久亚洲综合影院| 久久偷看各类wc女厕嘘嘘| 久久成人精品| 久久久精品免费国产四虎| 欧美亚洲另类久久综合婷婷| 久久精品国产亚洲av日韩| 国产69精品久久久久99尤物| 久久精品国产99久久久古代 | 超级97碰碰碰碰久久久久最新| 国产精品久久久久久久久鸭| 久久频这里精品99香蕉久| 久久综合狠狠综合久久激情 | 国产成人精品久久| 人人狠狠综合久久亚洲| 99久久免费只有精品国产| 久久久久亚洲精品无码蜜桃| 日日狠狠久久偷偷色综合0| 99久久精品这里只有精品| 精品精品国产自在久久高清| 久久天堂AV综合合色蜜桃网| 亚洲欧美日韩中文久久| 久久亚洲熟女cc98cm| 18禁黄久久久AAA片| 久久亚洲精品国产亚洲老地址| 久久这里有精品视频| 国产激情久久久久影院老熟女免费| 久久久久国产精品熟女影院| 亚洲精品乱码久久久久久| 伊人久久大香线蕉综合Av| 狠狠色综合网站久久久久久久高清 | 久久国产精品99国产精| 久久国产精品成人影院| 久久精品国产亚洲AV香蕉| 久久精品国产亚洲AV无码娇色| AAA级久久久精品无码片| 69久久夜色精品国产69| 91精品国产综合久久久久久| 久久99免费视频|