1. 程式人生 > >筆記搬到部落格 - nginx一步步整合lua模組

筆記搬到部落格 - nginx一步步整合lua模組

經過網路搜尋、整理、實踐筆記

 

前置條件:已安裝nginx

 

一 、安裝LuaJit

1.下載LuaJit  http://luajit.org/download.html

[[email protected]_6 source]$ wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz

2.安裝

2.1解壓:

[[email protected]_6 source]$ tar -zxvf LuaJIT-2.0.5.tar.gz

2.2進入解壓目錄

[[email protected]

_6 source]$ cd LuaJIT-2.0.5

2.3編譯

[[email protected]_6 LuaJIT-2.0.5]$ make PREFIX=/data/servers/luajit

2.4完成安裝

[[email protected]_6 LuaJIT-2.0.5]$ make install PREFIX=/data/servers/luajit

 

二、下載ngx_devel_kit (NDK) 

1.下載 ngx_devel_kit (NDK)   https://github.com/simpl/ngx_devel_kit/tags

[[email protected]_6 source]$ wget https://github.com/simplresty/ngx_devel_kit/archive/v0.3.0.tar.gz

2.解壓

[[email protected]_6 source]$ tar -zxvf v0.3.0.tar.gz

解壓後文件夾:ngx_devel_kit-0.3.0

 

三、下載 ngx_lua

1.下載 ngx_lua  https://github.com/openresty/lua-nginx-module/tags

[[email protected]

_6 source]$ wget https://github.com/openresty/lua-nginx-module/archive/v0.10.13.tar.gz

2.解壓

[[email protected]_6 source]$ tar -zxvf v0.10.13.tar.gz

解壓後文件夾:lua-nginx-module-0.10.13

 

四、檢視之前編譯引數

[[email protected]_6 source]$ nginx -V

configure arguments: --prefix=/data/servers/nginx --with-http_ssl_module --with-http_stub_status_module --with-openssl=/data/source/openssl-1.1.0c --with-threads

 

五、整合

1. 進入nginx安裝源目錄

[[email protected]_6 source]$ cd /data/servers/nginx-1.14.1/

2. 先執行環境變數

[[email protected]_6 nginx-1.14.1]$ export LUAJIT_LIB=/data/servers/luajit/lib

[[email protected]_6 nginx-1.14.1]$ export LUAJIT_INC=/data/servers/luajit/include/luajit-2.0

3. 備份之前的nginx

[[email protected]_6 nginx-1.14.1]$ cp /data/servers/nginx/sbin/nginx /data/servers/nginx/sbin/nginx.bak

4. 編譯nginx 增加之前ngxin -V檢查的引數

[[email protected]_6 nginx-1.14.1]$ ./configure --prefix=/data/servers/nginx --with-http_ssl_module --with-http_stub_status_module --with-openssl=/data/source/openssl-1.1.0c --with-threads --add-module=/data/source/ngx_devel_kit-0.3.0/ --add-module=/data/source/lua-nginx-module-0.10.13/

[[email protected]_6 nginx-1.14.1]$ make -j2 //使用2個執行緒執行

[[email protected]_6 nginx-1.14.1]$ make install

5. 如啟動nginx產生錯誤

nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory

將libluajit-5.1.so.2軟鏈至/lib64下

[[email protected]_6 ~]$ sudo ln -s /data/servers/luajit/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2

 

六、檢查lua是否整合成功

1. 開啟../conf/nginx.conf配置檔案,增加以下配置

location /hello_lua {

default_type 'text/plain';

content_by_lua 'ngx.say("hello, lua")';

}

2.重啟nginx

[[email protected]_6 conf]$ sudo nginx -s reload

3.訪問測試頁

訪問localhost/hello_lua會出現”hello, lua”表示安裝成功

 

七、整合redis - 測試通過後補錄

 

【強烈推薦!非廣告!】阿里雲雙11褥羊毛活動(10.29-11.12):https://m.aliyun.com/act/team1111?from=singlemessage&isappinstalled=0#/share?params=N.FF7yxCciiM.5rnfefip。新用 。新使用者低至一折購買【1核2GIM1年99元,2年199元,3年298元】【2核4GIM1年545元,2年927元,3年1227元】【2核8G5M3年2070元】,建議購買兩核的伺服器,1核的伺服器CPU使用率會有限制。老使用者可以加入我的戰隊,然後分享自己的連結,可以獲得紅包和25%的返現,我們的戰隊目前1000多位新人,目前排名第2,後面可以瓜分百萬現金(按拉新人數瓜分現金,拉的越多分的越多!不要自己重新開戰隊,後面不能參與瓜分現金)。