Nginx method steps for installing the lua nginx module module

  • 2020-05-15 03:42:03
  • OfStack

ngx_lua_module is an nginx http module that inlays the lua parser into nginx to parse and execute web backend scripts written in lua

Features are very good, you can check by yourself baidu, here is mainly to demonstrate 1, how to install lua-nginx-module module under Nginx

Before, of course, if you didn't install Nginx, and suspicion installation problems, can directly download openresty simple and easy to install, http: / / openresty org/cn/installation html (ali's Daniel chapter also spring, worship ~ ~ ~)

1. Download and install LuaJIT 2.1 (2.0 or 2.1 is support, the official recommendation 2.1) : http: / / luajit org/download html


cd /usr/local/src
wget http://luajit.org/download/LuaJIT-2.1.0-beta2.tar.gz
tar zxf LuaJIT-2.1.0-beta2.tar.gz
cd LuaJIT-2.1.0-beta2
make PREFIX=/usr/local/luajit
make install PREFIX=/usr/local/luajit

2. Download ngx_devel_kit (NDK) modules: https: / / github com/simpl/ngx_devel_kit/tags, do not need to install


cd /usr/local/src
wget https://github.com/simpl/ngx_devel_kit/archive/v0.2.19.tar.gz
tar -xzvf v0.2.19.tar.gz

3. Download the latest lua nginx - module modules: https: / / github com openresty/lua - nginx - module/tags, do not need to install


cd /usr/local/src
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.2.tar.gz
tar -xzvf v0.10.2.tar.gz

4. nginx-V view the compiled configuration


nginx -V

The author's configuration is as follows:

--prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-openssl=../openssl-1.0.2h --with-pcre=../pcre-8.38 --with-pcre-jit --with-ld-opt=-ljemalloc --with-ld-opt=-Wl,-rpath,/usr/local/luajit/lib --add-module=/usr/local/src/ngx_devel_kit-0.2.19 --add-module=/usr/local/src/lua-nginx-module-0.10.2

5. Enter the unzipped directory where nginx was installed before, and recompile the installation (in the configuration obtained by nginx-devel_kit-0.2.19 and ua-nginx-module-0.10.2). The final configuration is as follows:

Setting environment variables


export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.1

./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-openssl=../openssl-1.0.2h --with-pcre=../pcre-8.38 --with-pcre-jit --with-ld-opt='-ljemalloc' --with-ld-opt="-Wl,-rpath,/usr/local/luajit/lib" --add-module=/usr/local/src/ngx_devel_kit-0.2.19 --add-module=/usr/local/src/lua-nginx-module-0.10.2

6. Compile and install


make -j2
make install

7. Check to see if the build was successful

In/usr local/nginx/conf/nginx conf to add the following code:


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

Restart nginx:


service nginx restart

Visit 10.211.55.3/hello_lua and "hello, lua" will appear to indicate that the installation was successful


hello, lua

Related articles: