• <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年5月>
            2526272829301
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            享受編程

            常用鏈接

            留言簿(11)

            隨筆分類(159)

            隨筆檔案(224)

            文章分類(2)

            文章檔案(4)

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

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            OpenResty 它打包了標(biāo)準(zhǔn)的 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基本的第三方庫安裝進(jìn)去

            在/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 漂漂 閱讀(17533) 評論(0)  編輯 收藏 引用

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


            精品国产综合区久久久久久| 久久精品成人欧美大片| 一本色道久久88综合日韩精品| 91精品观看91久久久久久| 精品久久久久一区二区三区| 欧美国产精品久久高清| 久久亚洲AV无码精品色午夜 | 亚洲欧美日韩中文久久 | 久久综合亚洲色HEZYO国产| 武侠古典久久婷婷狼人伊人| 久久这里只有精品18| 日本久久久久久中文字幕| 狠狠色丁香久久婷婷综合| 91精品久久久久久无码| 久久精品毛片免费观看| 国产精品久久久久久久久软件| 久久国产乱子精品免费女| 欧洲人妻丰满av无码久久不卡| 国产女人aaa级久久久级| 99久久精品免费国产大片| 日本久久久久久中文字幕| 91亚洲国产成人久久精品网址| 亚洲AV无码1区2区久久| 久久精品免费一区二区| 欧美一区二区三区久久综合| 久久精品人妻中文系列| 99久久久精品| 国产69精品久久久久APP下载| 狠狠色狠狠色综合久久| 久久国产福利免费| 精品视频久久久久| 欧美成人免费观看久久| 亚洲精品国产字幕久久不卡| 久久久噜噜噜久久熟女AA片| 久久久WWW成人| 久久久久久久综合日本亚洲| 欧美一级久久久久久久大| 婷婷久久香蕉五月综合加勒比| 国产精品美女久久久免费| 青草国产精品久久久久久| 久久精品国产99久久久古代 |