nginx配置lua脚本

1.下载对应的安装包 

wget https://luajit.org/download/LuaJIT-2.0.4.tar.gz
wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.13.tar.gz

我这里也整理了一份(https://download.csdn.net/download/yangyongdehao30/78119103)

2.进行安装,记得luajit 要配置环境变量

tar -zxvf LuaJIT-2.0.5.tar.gz

cd LuaJIT-2.0.5

make && make install PREFIX=/usr/local/LuaJIT

vi /etc/profile 加入并使之生效

# lua

export LUAJIT_LIB=/usr/local/LuaJIT/lib

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

执行

source /etc/profile

3.增加nginx model编译

./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

lua-nginx-module-0.10.9rc7 和 ngx_devel_kit-0.3.0 替换为自己的路径即可

4. make   --> make install

5.查看nginx -V 

./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

/usr/local/LuaJIT/lib - 自己的 luaJIT的lib (如果安装luajit时没指定config 则为/usr/local/lib)

如无法启动,提示:[emerg] getpwnam(“www”) failed,则创建用户

/usr/sbin/groupadd -f www
/usr/sbin/useradd -g www www

 

6.修改nginx.cnf

location /lua {

        default_type text/html;

        access_by_lua_file /usr/local/nginx/conf/test.lua;

}

test.lua:

ngx.say("111");

请求 http:ip:port/lua 返回 1111

本文参考Nginx 使用Lua脚本 - winss - 博客园

你可能感兴趣的:(lua,nginx,运维)