溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Nginx如何添加lua模塊

發(fā)布時(shí)間:2022-06-02 14:17:11 來源:億速云 閱讀:440 作者:iii 欄目:大數(shù)據(jù)

這篇文章主要介紹“Nginx如何添加lua模塊”,在日常操作中,相信很多人在Nginx如何添加lua模塊問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”Nginx如何添加lua模塊”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!

安裝 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) 模塊是一個(gè)拓展 nginx 服務(wù)器核心功能的模塊,第三方模塊開發(fā)可以基于它來快速實(shí)現(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 中能直接運(yùn)行 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

進(jìn)入 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。

編譯報(bào)錯(cuò)應(yīng)該就是 lua 環(huán)境變量不對(duì)。

nginx -v 命令報(bào)錯(cuò)
./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 查看,無報(bào)錯(cuò)即可。

把原來的 nginx 備份為 nginx_old

cp objs/nginx 到原來的 nginx 并覆蓋。

在編譯目錄執(zhí)行

make upgrade

nginx 添加 lua 模塊

測(cè)試:

server{
 ...
 location /lua {
  default_type 'text/html';
  content_by_lua '
    ngx.say("hello, lua!")
  ';
 }
 ...
}

瀏覽器打開:

http://blog.13sai.com/lua

可以看到 hello, lua!

到此,關(guān)于“Nginx如何添加lua模塊”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI