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 服務(wù)器核心功能的模塊,第三方模塊開發(fā)可以基于它來快速實現(xiàn)。 NDK 提供函數(shù)和宏處理一些基本任務(wù), 減輕第三方模塊開發(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。
編譯報錯應(yīng)該就是 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!
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
使用Nginx搭建圖片服務(wù)器(windows環(huán)境下)
這篇文章主要介紹了使用Nginx搭建圖片服務(wù)器(windows環(huán)境下),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-06-06
nginx location中uri的截取的實現(xiàn)方法
這篇文章主要介紹了nginx location中uri的截取的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-04-04
nginx 多個location轉(zhuǎn)發(fā)任意請求或訪問靜態(tài)資源文件的實現(xiàn)
這篇文章主要介紹了nginx 多個location轉(zhuǎn)發(fā)任意請求或訪問靜態(tài)資源文件的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-11-11

