Nginx adds the implementation of the lua module

  • 2020-05-17 07:51:07
  • OfStack

Install lua


wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz 
tar -zxvf LuaJIT-2.0.5.tar.gz
cd LuaJIT-2.0.5
make && make install PREFIX=/usr/local/LuaJIT

etc/profile to join


# lua
export LUAJIT_LIB=/usr/local/LuaJIT/lib 
export LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.0

source etc/profile

Download the ngx_devel_kit module


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

The NDK (nginx development kit) module is a module that extends the core functions of the nginx server. The third module development can be realized quickly based on it. NDK provides functions and macros to handle some basic tasks, reducing the amount of code being developed by the third party module

Download the lua-nginx-module module


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

The lua-nginx-module module enables nginx to run lua directly

View the original compilation


nginx -V

Such as:
configure arguments: --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

Enter nginx original directory:


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

make only, make install is not implemented.

Compile error should be lua environment variable wrong.


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

 Solution: 
echo "/usr/local/LuaJIT/lib" >> /etc/ld.so.conf

ldconfig

After success, you can view nginx-V without any error.

Back up the original nginx to nginx_old

cp objs/nginx go to the original nginx and overlay.

Execute in the compile directory


make upgrade

Nginx adds the lua module

Testing:


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

Browser opens:

http://blog.13sai.com/lua

You can see hello, lua!


Related articles: