Linux system installation nginx Lua environment

Time:2021-10-22

Also refer to the official installation guide:lua-nginx-module Installation

This is my summary of installation for reference:

The latest version is requiredNginxLuaJIT,ngx_ devel_ Kit, Lua nginx module and other installation files:

Nginx
Luajit Lua or luajit are OK, but for performance reasons, it is recommended to install luajit
ngx_devel_kit
lua-nginx-module

Reference command Download:

?
1
2
3
4
$ curl -O http://nginx.org/download/nginx-1.10.1.tar.gz
$ curl -O http://luajit.org/download/LuaJIT-2.1.0-beta2.tar.gz
$ curl -L -O https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz
$ curl -L -O https://github.com/openresty/lua-nginx-module/archive/v0.10.5.tar.gz

Installing luajit

?
1
2
3
4
5
$ wget http://luajit.org/download/LuaJIT- .tar.gz
$ tar zxvf LuaJIT- .tar.gz
$ cd LuaJIT-
$ make
$ sudo make install

Compile and install Lua nginx module

?
1
2
3
4
5
6
7
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.1
 
cd nginx-1.10.1
./configure --prefix=/opt/nginx --with-ld-opt="-Wl,-rpath,/usr/local/lib" --add-module=/path/to/ngx_devel_kit-0.3.0 --add-module=/path/to/nginx/lua-nginx-module-0.10.5
make
make install

Dynamic module mode

Starting from nginx 1.9.11, the module can be compiled as a dynamic module. When executing the. / configure command, replace – add module = path with – add dynamic module = path. After compilation, load can be used in nginx.conf configuration_ Module to dynamically load this module:

?
1
2
3
load_module /path/to/modules/ndk_http_module.so;
load_module /path/to/modules/ngx_http_lua_module.so;
lua cjson install

Eureka zuul gateway

Lua runtime is required for installing and compiling cjson, and Lua in makefile needs to be modified before compilation_ VERSION、LUA_ INCLUDE_ DIR、LUA_ CMODULE_ Dir parameter to let the cjson module know the Lua library file and header file directory before normal compilation and installation.

Download and extract:

?
1
2
3
wget http://www.kyne.com.au/~mark/software/download/lua-cjson-2.1.0.tar.gz
tar -zxvf cjson-2.1.0.tar.gz
cd cjson-2.1.0

Modify makefile:

?
1
2
3
4
5
6
LUA_VERSION = luajit-2.1
LUA_INCLUDE_DIR = $(PREFIX)/include/$(LUA_VERSION)
LUA_CMODULE_DIR = $(PREFIX)/lib
 
make & sudo make install
sudo cp cjson.so /usr/local/lib/lua/5.1/