nginx安装lua模块

来源:互联网 发布:cnstorm和淘宝比哪个好 编辑:程序博客网 时间:2024/04/28 07:35

1、下载相应的nginx版本,http://nginx.org/en/download.html,安装过程略


2、安装lua或者luajit,http://luajit.org/download.html

yum install lua -y


3、下载模块https://github.com/openresty/lua-nginx-module/tags  https://github.com/simpl/ngx_devel_kit/releases/tag/v0.3.0rc1


4、安装模块

tar -xzvf lua-nginx-module-0.10.2.tar.gz

tar -xzvf ngx_devel_kit-0.3.0rc1.tar.gz 


./configure --prefix=/usr/local/nginx  --with-http_stub_status_module --with-http_ssl_module --with-http_secure_link_module --with-http_sub_module --add-module=../ngx_devel_kit-0.3.0rc1  --add-module=../lua-nginx-module-0.10.2

make

make install


5、测试lua脚本

在nginx.conf的server中添加如下内容


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


启动nginx会报 如下错误

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

此类问题通常使用ldconfig命令就能解决:

echo "/usr/local/lib" >/etc/ld.so.conf.d/lua.conf

ldconfig

重启nginx


访问http://127.0.0.1/hello  页面返回hello lua即安装成功




6、lua访问redis  

下载https://github.com/agentzh/lua-resty-redis.git

将lib中的resty 复制到/usr/local/config/nginx/


lua_package_path "/usr/local/nginx/conf/resty/?.lua;;";


0 0
原创粉丝点击