nginScript will work alongside NGINX's Lua scripting engine

Sep 24, 2015 19:58 GMT  ·  By

At the nginx.conf 2015 conference, Igor Sysoev, the creator of the NGINX Web server, announced the release of nginScript, a scripting engine that will let developers use JavaScript code to update an NGINX server's runtime configuration.

The thinking behind this new feature was to enhance NGINX's built-in Lua-based scripting utility with one based on JavaScript, a programming language that many more developers are fluent in.

"Scripting lets people do more in NGINX without having to write C modules," said Sysoev. "nginScript can be used for quick fixes, making NGINX configuration more convenient and operations more efficient."

ngingScript allows developers to filter and manage traffic at runtime

Technically, this was implemented by adding a new custom virtual machine and bytecode compiler to the NGINX core, which Sysoev says has "a very fast start-up and tear-down time."

Traffic goes through this VM, which allows HTTP traffic to be handled at runtime, with a very small delay.

Developers can use nginScript together with a special subset of the JavaScript syntax, which they can blend in with their regular configuration files, creating dynamic traffic filters that make the server behave in a certain way when a condition is met.

Sysoev says that nginScript can be successfully used against abusive traffic, by simplifying the procedures needed to filter, rate-limit, and deny requests.

Additionally, because of JavaScript's wide range of features, he also claims that nginScript could be used to break some of the functionality out of bulky apps, and integrate it into the platform (the NGINX server).

NGINX is not trying to be a Node.js clone

Since nginScript snippets can be stored in separate files and invoked when needed, some might say that NGINX might be putting the first stones in place to create their own Node.js version.

The company has anticipated these rumors and is clearly stating in nginScript's documentation that ngingScript is not to be an application server, and it recommends to be used only as a server configuration enhancement.

The documentation also confirms that NGINX's Lua scripting capabilities will continue to be developed alongside nginScript.

Below is a sample nginScript configuration snippet:

code
http {
    js_set $hello_world "
            var str = 'Hello World!';
            // JavaScript
            str;
    ";

    server {
        ...
        location /{
            return 200 $hello_world;
        }
    }
}