• <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
            <2018年5月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789


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

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            相冊

            Awesome

            Blog

            Book

            GitHub

            Link

            搜索

            •  

            積分與排名

            • 積分 - 215511
            • 排名 - 118

            最新評論

            閱讀排行榜

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

            作者:楊鑫奇

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

            主要原因是:

            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的內容
            在nginx.conf中添加lualib的路徑
            lua_package_path "/usr/local/lualib/resty/websocket/?.lua;;";

            我這里是獨立開的yagamiko.conf,添加websocket:
            在server段內,修改添加以下內容:

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

            這個是Aapo Talvensaari同學寫的測試代碼: 

            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 思月行云 閱讀(2348) 評論(0)  編輯 收藏 引用 所屬分類: Nginx\Openresty
            人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 色综合久久天天综合| 久久国产精品99精品国产| 久久精品国产亚洲麻豆| 久久精品国产精品亚洲毛片| 久久久久国产精品| 亚洲精品第一综合99久久| 久久精品中文闷骚内射| 久久无码一区二区三区少妇| 久久无码人妻一区二区三区| 久久国产精品偷99| 色婷婷综合久久久中文字幕| 久久久精品国产Sm最大网站| 性做久久久久久久| 日韩欧美亚洲综合久久| 超级碰久久免费公开视频| 久久人妻AV中文字幕| 久久99精品久久久久久秒播| 久久精品人人槡人妻人人玩AV| 久久久久亚洲精品中文字幕| 国产一区二区三区久久精品| 亚洲中文字幕无码一久久区 | 亚洲国产成人久久精品99 | 成人亚洲欧美久久久久| 久久国产精品一国产精品金尊| 亚洲欧洲久久av| 日本高清无卡码一区二区久久| 一级做a爰片久久毛片人呢| 久久亚洲欧美国产精品 | 蜜臀av性久久久久蜜臀aⅴ麻豆| 欧美久久一区二区三区| 狠狠人妻久久久久久综合| 狠狠色伊人久久精品综合网| 青青草原1769久久免费播放| 2021少妇久久久久久久久久| 精品无码久久久久久午夜| 久久久精品国产sm调教网站 | 久久精品不卡| 日日狠狠久久偷偷色综合免费| 色婷婷久久久SWAG精品| 亚洲精品午夜国产va久久|