nginScript - JavaScript Meets NGINX

September 25th, 2015 | By Paulo Silva | 2 min read

Nginx, a well-known HTTP server, has announced nginScript, a JavaScript-based Configuration Language. This custom JavaScript implementation is used to enable dynamic configuration.

NGINX is also used as a mail server, reverse proxy, or an open-source, high-performance, low-maintenance WAF. Going even further, in Evan Miller’s words, it could be Batman’s belt.

NGINX Explained

NGINX is free, open-source, and truly performant, with a really thin but complex core.

Most of the features are provided as modules, which are written in C language and compiled together with the core (instead of dynamically linked).

The notorious lack of documentation makes module development painful and time-consuming: any mistake and NGINX’s performance will drop. We’ve been there! In order to ease this process, at least for smaller features and tasks, NGINX introduced Perl and Lua Scripting.

Lua Scripting

Video game companies spread Lua Scripting to allow users to create their own game levels and automate tasks. It is also used in products like Redis, Photoshop, and VLC Media Player. However, Lua is not a so common programming language like, for instance, JavaScript, the #1 programming language on GitHub (Q4/14).

nginScript launch

NGINX launched nginScript with a wide range of potential uses. NGINX is a subset of JavaScript for NGINX. It doesn’t offer all of JavaScript's functionalities, but anyone who has ever written a few lines of JavaScript can now confidently extend NGINX's capabilities.

nginScript's potential uses, according to Igor Sysoev, NGINX’s author:

  • Defend against security threats: nginScript can dynamically respond to abusive traffic sources by rate-limiting or denying requests.

  • Gain richer control over traffic. You can implement flexible control over how traffic is routed using the information in the request or other sources.

  • Consolidate functions across applications: You can move duplicate functionality out of applications and into the application delivery platform.

  • Speed application development with function libraries: nginScript code can be developed, reused, improved, stored, and shared.”

And this is what the famous “hello world” example would look like

location / {   
    js_run "       
    var res;       
    res = $r.response;       
    res.status = 200;       
    res.send('Hello World!');       

This is a sign of JavaScript's growth as its adoption spreads to new contexts. It is becoming the universal programming language.

Learn more about nginScript and how to harness the power and convenience of JavaScript for each request with the NGINX JavaScript module.


The leader in client-side Web security. With Jscrambler, JavaScript applications become self-defensive and capable of detecting and blocking client-side attacks like Magecart.

View All Articles

Must read next

Web Development

Scaling Node.js Socket Server with Nginx and Redis

Getting applications to handle a huge volume of requests is no simple matter. Learn how to scale your Node.js application with Nginx and Redis.

November 9, 2018 | By Nairi Haroutiounian | 13 min read

Web Development

Setting Up Angular Server-Side Rendering (SSR)

Server-side rendering can bring several benefits to performance and SEO. In this post, we explain how to create an Angular Universal app with SSR.

November 6, 2019 | By Ahmed Bouchefra | 5 min read

Section Divider

Subscribe to Our Newsletter