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 it's handling of branching logic.
Sometimes it is necessary to have more complex workflows invoked on a per-request basis however. Luckily an NGINX LUA module exists that allow 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 can not currently download a packaged version of OpenResty NGINX for Ubuntu, you need to compile it from source; here is a little helper to get you started!
sudo su version=184.108.40.206 # 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 2 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!
Part II: For examples of NGINX Lua integration, check out "Supercharging NGINX with Lua (Part 2)".
Part III: For more advanced examples of NGINX Lua, check out "Supercharging NGINX with Lua (Part 3)".