August 2017
Intermediate to advanced
278 pages
8h 53m
English
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. The first recipe returns a basic string:
location /simpletest {
default_type 'text/plain';
content_by_lua_block {
ngx.say('This is a simple test!')
}
}
If you browse to the URL (or use cURL to make the request), you should simply get This is a simple test as the HTTP response. Running a simple Apache Benchmark against this URL (just to show a baseline performance) shows that it can serve this URL over 20,000 times a second on a modestly resourced VM. While the code isn't overly complex, ...
Read now
Unlock full access