• <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年6月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            享受編程

            常用鏈接

            留言簿(11)

            隨筆分類(159)

            隨筆檔案(224)

            文章分類(2)

            文章檔案(4)

            經(jīng)典c++博客

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

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

            如果需要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
            會出現(xiàn)“hello,lua”

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

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

             

            location /getXxxInfo {
                        default_type 
            'text/plain';
                        content_by_lua 
            '
               
                   
            --先從memcache提取數(shù)據(jù)

                            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
                
                
            --數(shù)據(jù)不在memcache中 從數(shù)據(jù)庫提取并放到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 漂漂 閱讀(17518) 評論(0)  編輯 收藏 引用

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            狠狠综合久久综合88亚洲| 91精品观看91久久久久久| 久久99精品久久久久久齐齐| 久久人人爽人人爽人人片AV不| 狠狠色丁香久久婷婷综合蜜芽五月| 久久99精品久久久久久野外| 久久久噜噜噜久久中文字幕色伊伊| 久久国产精品免费一区| 久久无码国产专区精品| 99国产精品久久| 久久这里都是精品| 国产精品无码久久四虎| 亚洲∧v久久久无码精品| 久久影院久久香蕉国产线看观看| 久久久亚洲AV波多野结衣 | 久久99热国产这有精品| 麻豆国内精品久久久久久| 97久久精品人妻人人搡人人玩| 久久99热这里只有精品国产| 狠狠色噜噜色狠狠狠综合久久| 99久久国产热无码精品免费| 88久久精品无码一区二区毛片| 午夜欧美精品久久久久久久| 国内精品久久久久久久久电影网 | 久久丫精品国产亚洲av不卡| 久久99这里只有精品国产| 伊人久久无码精品中文字幕| 国内精品人妻无码久久久影院导航| 色天使久久综合网天天| av色综合久久天堂av色综合在| 亚洲成色WWW久久网站| 国内精品伊人久久久久av一坑| 91精品日韩人妻无码久久不卡| 亚洲精品第一综合99久久| 亚洲乱码精品久久久久..| 国产精品免费久久| 99久久精品日本一区二区免费| 亚洲欧洲久久av| 99久久免费只有精品国产| 久久国产精品无码一区二区三区 | 久久久精品国产sm调教网站|