如何安裝nginx_lua_module模塊

摘要:

本文記錄如何安裝ngx_lua模塊

nginx_lua_module是由淘寶的工程師清無(王曉哲)和春來(章亦春)所開發的nginx第三方模塊,它能將lua語言嵌入到nginx配置中,從而使用lua就極大增強了nginx的能力

http://wiki.nginx.org/HttpLuaModule


正文:

1 下載luajit 2.0並安裝

http://luajit.org/download.html

我是直接使用源碼make && make install

所以lib和include是直接放在/usr/local/lib和usr/local/include


2 下載nginx源碼,解壓

注意版本號,如果機子上已經裝了nginx,不想升級的話,請使用/to/nginx/sbin/nginx –v

來查看版本號


3  下載ngx_devel_kit HERE 解壓

4  下載nginx_lua_module HERE 解壓


5 進入nginx源碼文件夾

cd nginx-1.0.11/


6 導入環境變量,編譯

export LUAJIT_LIB=/usr/local/lib    #這個很有可能不一樣    
export LUAJIT_INC=/usr/local/include/luajit-2.0  #這個很有可能不一樣


./configure --prefix=/opt/nginx \    #nginx的安裝路徑    
--add-module=/path/to/ngx_devel_kit \   #ngx_devel_kit 的源碼路徑    
--add-module=/path/to/lua-nginx-module  #nginx_lua_module 的源碼路徑


make -j2    
make install


7 測試是否成功:

nginxconfig中加入


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


使用/to/nginx/sbin/nginx –t 檢查nginx配置,此時應該沒有報錯


8 /to/nginx/sbin/nginx   #啓動nginx

或者/to/nginx/sbin/nginx –s reload #重啓nginx



訪問192.168.100.1/hello

會出現“hello,lua”


安裝成功!




補充:

1.如遇到找不到庫文件
echo “/usr/local/lib” > /etc/ld.so.conf.d/usr_local_lib.conf
ldconfig
即可
2./usr/local/nginx/sbin/nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory  
在 Nginx 編譯時,需要指定 RPATH,記得加入下面選項:
./configure --with-ld-opt="-Wl,-rpath,$LUAJIT_LIB"  
或者export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH



相關鏈接:
http://www.cnblogs.com/yjf512/archive/2012/03/27/2419577.html

http://www.th7.cn/system/lin/201311/47418.shtml
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章