How it works...
We start by loading the CJSON and Lua OpenResty DNS modules and initiating the DNS module by setting the nameservers to 8.8.8.8 (Google's free open resolver).
Then, we parse the GET argument, named domain. Through the NGINX API, Lua can call this directly via the domain name. If the get variable you wanted was named shop, you could have called it via ngx.var.arg_shop.
This is then validated by ensuring the variable is set (for example, the GET argument was passed) and then checking for a basic domain. The formats of the regular expressions within Lua are slightly different to the more common Perl-Compatible Regular Expressions (PCRE), but the concept remains the same. We ensure that the domains start with alphanumeric characters ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access