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

            經典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 漂漂 閱讀(17518) 評論(0)  編輯 收藏 引用
            人妻精品久久久久中文字幕69| 国产综合免费精品久久久| 中文成人久久久久影院免费观看| 一本色道久久88综合日韩精品 | 午夜精品久久久久久影视777| 久久伊人精品一区二区三区| 久久久国产乱子伦精品作者| 久久97久久97精品免视看| 伊人久久大香线蕉综合Av| AAA级久久久精品无码区| 久久国语露脸国产精品电影| 2020最新久久久视精品爱| 久久水蜜桃亚洲av无码精品麻豆| 久久精品国产亚洲Aⅴ香蕉| 久久精品亚洲日本波多野结衣| 香蕉久久影院| 精品国产乱码久久久久久浪潮 | 久久亚洲中文字幕精品有坂深雪 | 中文无码久久精品| 亚洲第一永久AV网站久久精品男人的天堂AV | 免费观看成人久久网免费观看| 中文成人久久久久影院免费观看| 日本精品久久久中文字幕| 日韩av无码久久精品免费| 亚洲精品视频久久久| 久久久久久av无码免费看大片| 九九久久99综合一区二区| 色偷偷久久一区二区三区| 久久精品免费全国观看国产| 日韩久久无码免费毛片软件| 国产精品丝袜久久久久久不卡| 精品一区二区久久| 国产精品久久99| 久久99精品国产自在现线小黄鸭| 久久精品国产久精国产果冻传媒| 思思久久精品在热线热| 亚洲国产精品综合久久网络 | 久久精品国产欧美日韩99热| 少妇被又大又粗又爽毛片久久黑人 | 国色天香久久久久久久小说| 午夜精品久久久久久影视riav|