Supercharging NGINX With Lua: Part I
Sometimes, we need more complex workflows invoked on a per-request basis. A NGINX LUA module exists that allows us to inject our own Lua handlers into the traffic flow.
Join the DZone community and get the full member experience.Join For Free
NGINX is a really really fantastic piece of software. It is supremely flexible and handles all kinds of traffic orchestration workloads. One place that NGINX has received commentary, however, is in its handling of branching logic.
Sometimes, it is necessary to have more complex workflows invoked on a per-request basis, however. Luckily, a NGINX Lua module exists that allows us to simply inject our own Lua handlers into the traffic flow. Lua is a great fit as an embedded language because of its size, simplicity and JIT-compiled speed.
Getting Lua for NGINX
Unfortunately, adding the Lua module to NGINX on your own requires compilation of the module, which itself requires some tricky dependencies:
Ubuntu Install Cheatsheet
Because you cannot currently download a packaged version of OpenResty NGINX for Ubuntu, you need to compile it from the source. Here is a little helper to get you started!
sudo su version=220.127.116.11 # install dependencies apt-get install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl make build-essential # download & untar curl -s -o openresty-$version.tar.gz https://openresty.org/download/openresty-$version.tar.gz tar -xvf openresty-$version.tar.gz cd openresty-$version # configure & make ./configure --with-pcre-jit --with-ipv6 --with-stream --with-http_realip_module --with-http_stub_status_module --prefix=/opt/openresty make -j8 make install # NOTE: installs openresty to: /opt/openresty) # NOTE: installs nginx to: /opt/nginx/openresty/nginx)
Part II of this series will illustrate some examples of how we can now make use of our brand new supercharged NGINX-with-Lua to do some custom request handling.
Published at DZone with permission of Vic van Gool, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.