Nginx安装lua支持

Nginx安装lua支持

需要LuaJIT-2.0.4.tar.gzngx_devel_kitlua-nginx-module

1.下载安装LuaJIT-2.0.4.tar.gz

wget -c http://luajit.org/download/LuaJIT-2.0.4.tar.gz

tar xzvf LuaJIT-2.0.4.tar.gz

cd LuaJIT-2.0.4

make install PREFIX=/usr/local/luajit

 

#注意环境变量!

export LUAJIT_LIB=/usr/local/luajit/lib

export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0

2.下载解压ngx_devel_kit

wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz

tar -xzvf v0.3.0.tar.gz

3.下载解压lua-nginx-module

wget https://github.com/openresty/lua-nginx-module/archive/v0.10.8.tar.gz

tar -xzvf v0.10.8.tar.gz

 

4.下载安装nginx-1.10.3.tar.gz

wget http://nginx.org/download/nginx-1.10.3.tar.gz

tar -xzvf nginx-1.10.3.tar.gz

cd nginx-1.10.3

./configure --add-module=/opt/soft/ngx_devel_kit-0.3.0 --add-module=/opt/soft/lua-nginx-module-0.10.8

#注意ngx_devel_kitlua-nginx-module以实际解压路径为准

make -j2

make install

 

注:报错gcc需要安装,可以执行

yum install -y gcc g++ gcc-c++

依赖报错,可以执行

yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel

 

5.验证

#nginx做成命令

ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx

cd /usr/local/nginx/conf/

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");

 

#启动nginx(已经做了软连接了,可以在任何目录启动)

nginx

 

注:

报错nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory 可以执行

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

具体source的路径已实际安装路径为准

 

 

访问:

http://127.0.0.1/hello

显示:hello, lua

http://127.0.0.1/lua

显示:hello world

 

到这里确定安装成功。

posted @ 2017-05-15 13:47  aoeiuv  阅读(18440)  评论(0编辑  收藏  举报