1.下載stream-lua-nginx-module模塊:nginx
(https://github.com/openresty/stream-lua-nginx-module#installation)github地址git
cd /usr/local/openrestygithub
命令:git clone https://github.com/openresty/stream-lua-nginx-module.gitsocket
2.添加環境變量:tcp
export LUAJIT_LIB=/usr/local/openresty/luajit/lib
export LUAJIT_INC=/usr/local/openresty/luajit/include/luajit-2.1學習
3.編譯stream-lua-nginx-modulelua
wget http://openresty.org/download/ngx_openresty-1.9.7.4.tar.gzrest
tar -zxvf ngx_openresty-1.9.7.4.tar.gzserver
cd ngx_openresty-1.9.7.4圖片
輸入nginx -V命令,將參數添加上來便可
./configure --prefix=/usr/local/openresty --with-cc-opt='-O2 -I/usr/local/Cellar/openssl/1.0.2h_1/include/ -I/usr/local/Cellar/pcre/8.39/include/' --with-stream --with-stream_ssl_module --add-module=/usr/local/openresty/stream-lua-nginx-module --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -L/usr/local/Cellar/openssl/1.0.2h_1/lib/ -L/usr/local/Cellar/pcre/8.39/lib/' --with-http_ssl_module
make
make install
編譯安裝完後查看nginx參數:
請看圖片最後!!!,此時代表已經安裝成功
4.學習stream模塊:
在nginx.conf文件中加上紅色框框內代碼,便可構建一個tcp server,端口號爲1234
5.鏈接socket tcp服務端:
法一:經過telnet方法驗證
法二:經過socket 鏈接來驗證:
此時代表stream的tcp server已經建立成功啦!