Getting started with OpenResty Lua
One of the key powers of OpenResty is the built-in Lua scripting language. For those not familiar with Lua, it's a high-performance, yet lightweight scripting language. This is why, when it's combined with the NGINX event engine, it results in a very powerful combination.
Being a dynamically typed and interpreted language makes Lua similar to other scripting languages, such as JavaScript, but there are some subtle differences (especially syntax-wise). If you're new to Lua, then it's worthwhile reading through a few basic tutorials to familiarize yourself with the syntax and differences.
Getting ready
For this recipe, we'll use the standard OpenResty modules, so no further changes are required to get started.
How to do it...
We'll start with using one of the most basic functions in OpenResty and Lua, which is the content_by_lua_block
block directive. This allows us to insert Lua code directly in line with our NGINX configuration, providing rapid and dynamic changes...