Alex的博客

本博客的文章均为原创,是本人从事行业多年来所遇见一些小问题的解决心得,希望可以帮助到大家!



nginx 添加lua扩展

环境:

centos6 x64

nginx1.12


lua 下载地址:

http://luajit.org/download.html

ngx_devel_kit 下载地址

https://github.com/simpl/ngx_devel_kit/releases

lua-nginx-module下载地址

https://github.com/openresty/lua-nginx-module/tags


首先执行nginx -V 把之前的编译信息记录下来 后面有用


wget http://luajit.org/download/LuaJIT-2.0.5.zip

unzip -x LuaJIT-2.0.5.zip

cd LuaJIT-2.0.5

make install PREFIX=/software/luajit

ls /software/luajit/

export LUAJIT_LIB=/software/luajit/lib

export LUAJIT_INC=/software/luajit/include/luajit-2.0


wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.1rc1.zip

unzip -x v0.3.1rc1.zip

wget https://github.com/openresty/lua-nginx-module/archive/v0.10.12rc2.zip

unzip -x v0.10.12rc2.zip

cp -rf ngx_devel_kit-0.3.1rc1 /software/

cp -rf lua-nginx-module-0.10.12rc2 /software/

cp -rf lua-resty-redis-0.15 /software/

cp -rf redis2-nginx-module-0.15rc1 /software/

cd /software/

ln -s lua-nginx-module-0.10.12rc2/ lua-nginx-module

ln -s ngx_devel_kit-0.3.1rc1/ ngx_devel_kit

ln -s  lua-resty-redis-0.15/  lua-resty-redis

ln -s redis2-nginx-module-0.15rc1/ redis2-nginx-module

cd /data/software/nginx-1.12.2

./configure  --user=nginx --group=nginx --prefix=/software/nginx-1.12.2/ --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --add-module=/software/incubator-pagespeed-ngx-1.12.34.3-stable --with-cc=/opt/rh/devtoolset-2/root/usr/bin/gcc --add-module=/software/naxsi/naxsi_src/ --add-module=/software/ngx_devel_kit --add-module=/software/lua-nginx-module

make -j2

make install


/software/nginx-1.12.2/sbin/nginx -t

如果报错:

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

执行:

ln -s /software/luajit/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2


/software/nginx-1.12.2/sbin/nginx -t


测试:

vi nginx.conf


#lua指令方式
#在server 中添加一个localtion
location /hello {
            default_type 'text/plain';
            content_by_lua 'ngx.say("hello, lua")';
        }
#lua文件方式

#在server 中添加一个localtion
location /lua {
    default_type 'text/html';
    content_by_lua_file conf/lua/test.lua; #相对于nginx安装目录
}
#test.lua文件内容
ngx.say("hello world");

/software/nginx-1.12.2/sbin/nginx


然后访问url:


http://127.0.0.1/hello

显示:hello, lua

http://127.0.0.1/lua

显示:hello world

说明安装成功



浏览35  评论0  Alex于 2018-1-21 18:54
发言