Nginx添加lua模塊的實現(xiàn)方法
安裝 lua
wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz tar -zxvf LuaJIT-2.0.5.tar.gz cd LuaJIT-2.0.5 make && make install PREFIX=/usr/local/LuaJIT
etc/profile 加入
# lua export LUAJIT_LIB=/usr/local/LuaJIT/lib export LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.0
source etc/profile
下載 ngx_devel_kit 模塊
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
NDK (nginx development kit) 模塊是一個拓展 nginx 服務器核心功能的模塊,第三方模塊開發(fā)可以基于它來快速實現(xiàn)。 NDK 提供函數(shù)和宏處理一些基本任務, 減輕第三方模塊開發(fā)的代碼量
下載 lua-nginx-module 模塊
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.9rc7.tar.gz
lua-nginx-module 模塊使 nginx 中能直接運行 lua
查看原始編譯
nginx -V
如:
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_sub_module --with-http_v2_module
進入 nginx 原始目錄:
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_sub_module --with-http_v2_module --add-module=/root/lua-nginx-module-0.10.9rc7/ --add-module=/root/ngx_devel_kit-0.3.0
只 make,不執(zhí)行 make install。
編譯報錯應該就是 lua 環(huán)境變量不對。
nginx -V 命令報錯 ./nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory 解決: echo "/usr/local/LuaJIT/lib" >> /etc/ld.so.conf ldconfig
成功之后可以 nginx -V 查看,無報錯即可。
把原來的 nginx 備份為 nginx_old
cp objs/nginx 到原來的 nginx 并覆蓋。
在編譯目錄執(zhí)行
make upgrade
Nginx 添加 lua 模塊
測試:
server{
...
location /lua {
default_type 'text/html';
content_by_lua '
ngx.say("hello, lua!")
';
}
...
}
瀏覽器打開:
http://blog.13sai.com/lua
可以看到 hello, lua!
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持本站。
版權聲明:本站文章來源標注為YINGSOO的內容版權均為本站所有,歡迎引用、轉載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內容涉嫌侵權,請聯(lián)系alex-e#qq.com處理。
關注官方微信