• <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>
            Fork me on GitHub
            隨筆 - 215  文章 - 13  trackbacks - 0
            <2017年3月>
            2627281234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678


            專注即時通訊及網(wǎng)游服務(wù)端編程
            ------------------------------------
            Openresty 官方模塊
            Openresty 標(biāo)準(zhǔn)模塊(Opm)
            Openresty 三方模塊
            ------------------------------------
            本博收藏大部分文章為轉(zhuǎn)載,并在文章開頭給出了原文出處,如有再轉(zhuǎn),敬請保留相關(guān)信息,這是大家對原創(chuàng)作者勞動成果的自覺尊重!!如為您帶來不便,請于本博下留言,謝謝配合。

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            相冊

            Awesome

            Blog

            Book

            GitHub

            Link

            搜索

            •  

            積分與排名

            • 積分 - 216773
            • 排名 - 118

            最新評論

            閱讀排行榜

            https://www.cnblogs.com/scotoma/p/3330190.html

            作者:楊鑫奇

            關(guān)注Openresty很久了,期待支持websocket終于出來了,看到Aapo Talvensaari同學(xué)寫的文章https://medium.com/p/1778601c9e05,興奮下也來測試下,之前用websocket做即時通訊,還是基于socket.io的例子,現(xiàn)在用nginx來做...初嘗試下,竟然報錯了,章哥的解答在這里:
            https://github.com/agentzh/lua-resty-websocket/issues/2 ,現(xiàn)在配置成功了,將自己的配置過程寫下來,希望對大家有所幫助.

            主要原因是:

            websocket依賴于 lua-nginx-module,得用最新版本的,下面是章哥給的配置.
            我用最新的1.4.2.7編譯并測試成功的了.

            到自己的目錄下:
            下載最新版本的 openresty 和 lua-nginx-module 然后安裝:
            wget http://openresty.org/download/ngx_openresty-1.4.2.7.tar.gz
            tar zxvf ngx_openresty-1.4.2.7.tar.gz
            git clone https://github.com/chaoslawful/lua-nginx-module.git
            cd lua-nginx-module
            git checkout -b websocket origin/websocket
            cd ../ngx_openresty-1.4.2.7/bundle
            rm -Rf ngx_lua-0.8.9
            ln -s ../../lua-nginx-module ngx_lua-0.8.9
            cd ..
            ./configure -with-luajit -prefix=/usr/local 
            gmake && gmake install

            安裝完成后
            cd ../
            git clone https://github.com/agentzh/lua-resty-websocket.git
            拷貝websocket到lualib目錄下
            cp -r lua-resty-websocket/lib/resty/websocket /usr/local/lualib/resty/

            配置自己的nginx conf的內(nèi)容
            在nginx.conf中添加lualib的路徑
            lua_package_path "/usr/local/lualib/resty/websocket/?.lua;;";

            我這里是獨(dú)立開的yagamiko.conf,添加websocket:
            在server段內(nèi),修改添加以下內(nèi)容:

            listen 80 default so_keepalive=2s:2s:8;

            這個是Aapo Talvensaari同學(xué)寫的測試代碼: 

            location /1.0/websocket {

              lua_socket_log_errors off;

              lua_check_client_abort on;

              content_by_lua '

                local server = require "resty.websocket.server"

                local wb, err = server:new{

                timeout = 5000,  -- in milliseconds

                max_payload_len = 65535,

                }

                if not wb then

                  ngx.log(ngx.ERR, "failed to new websocket: ", err)

                  return ngx.exit(444)

                end

                while true do

                  local data, typ, err = wb:recv_frame()

                  if wb.fatal then

                    ngx.log(ngx.ERR, "failed to receive frame: ", err)

                    return ngx.exit(444)

                  end

                  if not data then

                    local bytes, err = wb:send_ping()

                    if not bytes then

                      ngx.log(ngx.ERR, "failed to send ping: ", err)

                      return ngx.exit(444)

                    end

                  elseif typ == "close" then break

                  elseif typ == "ping" then

                    local bytes, err = wb:send_pong()

                    if not bytes then

                      ngx.log(ngx.ERR, "failed to send pong: ", err)

                      return ngx.exit(444)

                    end

                  elseif typ == "pong" then

                    ngx.log(ngx.INFO, "client ponged")

                  elseif typ == "text" then

                    local bytes, err = wb:send_text(data)

                    if not bytes then

                      ngx.log(ngx.ERR, "failed to send text: ", err)

                      return ngx.exit(444)

                    end

                  end

                end

                wb:send_close()

              ';

            }

            然后重新啟動nginx就可以了...

            使用 這個哥們提到的測試html,就可以了 https://medium.com/p/1778601c9e05

            <html>
            <head>
            <script>
            var ws = null;
            function connect() {
              
            if (ws !== nullreturn log('already connected');
              ws 
            = new WebSocket('ws://ko.local.freeflare.com/1.0/websocket');
              ws.onopen = function () {
                log('connected');
              };
              ws.onerror 
            = function (error) {
                log(error);
              };
              ws.onmessage 
            = function (e) {
                log('recv: ' 
            + e.data);
              };
              ws.onclose 
            = function () {
                log('disconnected');
                ws 
            = null;
              };
              
            return false;
            }
            function disconnect() {
              
            if (ws === nullreturn log('already disconnected');
              ws.close();
              
            return false;
            }
            function send() {
              
            if (ws === nullreturn log('please connect first');
              
            var text = document.getElementById('text').value;
              document.getElementById('text').value 
            = "";
              log('send: ' 
            + text);
              ws.send(text);
              
            return false;
            }
            function log(text) {
              
            var li = document.createElement('li');
              li.appendChild(document.createTextNode(text));
              document.getElementById('log').appendChild(li);
              
            return false;
            }
            </script>
            </head>
            <body>
              <form onsubmit="return send();">
                <button type="button" onclick="return connect();">
                  Connect
                </button>
                <button type="button" onclick="return disconnect();">
                  Disconnect
                </button>
                <input id="text" type="text">
                <button type="submit">Send</button>
              </form>
              <ol id="log"></ol>
            </body>
            </html>

            測試....這里注意在同一個域名下就好了....

            測試成功了....


            posted on 2018-05-04 11:15 思月行云 閱讀(2371) 評論(0)  編輯 收藏 引用 所屬分類: Nginx\Openresty
            久久综合色老色| 久久久久久狠狠丁香| 精品国产青草久久久久福利| 亚洲Av无码国产情品久久| 久久精品免费全国观看国产| 久久久久无码精品国产| 国产女人aaa级久久久级| 亚洲国产成人久久一区WWW| 国产精品一区二区久久国产| 久久精品二区| 久久综合给久久狠狠97色| 久久99精品久久久久久噜噜| 久久亚洲AV成人出白浆无码国产| 久久AAAA片一区二区| 国产一区二区精品久久| 久久婷婷午色综合夜啪| 精品久久久久久综合日本| 久久久久亚洲国产| A级毛片无码久久精品免费| 久久精品成人欧美大片| 国产精品久久久久乳精品爆| 久久精品夜夜夜夜夜久久| 久久久久久免费视频| 久久夜色精品国产| 99久久精品免费观看国产| 99re久久精品国产首页2020| 亚洲精品tv久久久久久久久| 青青草国产97免久久费观看| 久久精品中文字幕第23页| 天天爽天天爽天天片a久久网| 久久99精品久久久久久hb无码| 丁香色欲久久久久久综合网| 一本色道久久综合| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 亚洲国产成人久久精品99| 狠狠精品干练久久久无码中文字幕 | 久久美女人爽女人爽| 久久er热视频在这里精品| 国产精品美女久久久久久2018| 欧美va久久久噜噜噜久久| 99久久精品日本一区二区免费|