Mercurial > hg > nginx-site
view xml/en/docs/njs/index.xml @ 2846:fdf1464e1977
Moved banner to the external file to make partial rollout possible.
An idea is to have several banners and show them with different probability
specified by split directive in the nginx.conf
author | Sergey Budnevitch <sb@waeme.net> |
---|---|
date | Tue, 10 May 2022 18:07:27 +0400 |
parents | 8831b3d9f332 |
children | bd8482c5a7fe |
line wrap: on
line source
<?xml version="1.0"?> <!-- Copyright (C) Nginx, Inc. --> <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> <article name="njs scripting language" link="/en/docs/njs/index.html" lang="en" rev="32" toc="no"> <section id="summary"> <para> njs is a subset of the JavaScript language that allows extending nginx functionality. njs is created in compliance with <link url="http://www.ecma-international.org/ecma-262/5.1/">ECMAScript 5.1</link> (strict mode) with some <link url="http://www.ecma-international.org/ecma-262/6.0/">ECMAScript 6</link> and later extensions. The compliance is still <link doc="compatibility.xml">evolving</link>. </para> </section> <section id="links"> <para> <list type="bullet"> <listitem> <link doc="install.xml"/> </listitem> <listitem> <link doc="changes.xml"/> </listitem> <listitem> <link doc="reference.xml"/> </listitem> <listitem> <link url="https://github.com/nginx/njs-examples/">Examples</link> </listitem> <listitem> <link doc="compatibility.xml"/> </listitem> <listitem> <link doc="cli.xml"/> </listitem> <listitem> <link id="tested_os_and_platforms">Tested OS and platforms</link> </listitem> </list> </para> <para> <list type="bullet"> <listitem> <link doc="../http/ngx_http_js_module.xml"> ngx_http_js_module</link> </listitem> <listitem> <link doc="../stream/ngx_stream_js_module.xml"> ngx_stream_js_module</link> </listitem> </list> </para> <para> <list type="bullet"> <listitem> <link doc="typescript.xml"/> </listitem> <listitem> <link doc="node_modules.xml"/> </listitem> </list> </para> </section> <section id="usecases" name="Use cases"> <para> <list type="bullet"> <listitem> Complex access control and security checks in njs before a request reaches an upstream server </listitem> <listitem> Manipulating response headers </listitem> <listitem> Writing flexible asynchronous content handlers and filters </listitem> </list> See <link url="https://github.com/nginx/njs-examples/">examples</link> and <link url="https://www.nginx.com/blog/tag/nginx-javascript-module/">blog posts</link> for more njs use cases. </para> </section> <section id="example" name="Basic HTTP Example"> <para> To use njs in nginx: <list type="bullet"> <listitem> <para> <link doc="install.xml">install</link> njs scripting language </para> </listitem> <listitem id="hello_world"> <para> create an njs script file, for example, <path>http.js</path>. See <link doc="reference.xml">Reference</link> for the list of njs properties and methods. <example> function hello(r) { r.return(200, "Hello world!"); } export default {hello}; </example> </para> </listitem> <listitem> <para> in the <path>nginx.conf</path> file, enable <link doc="../http/ngx_http_js_module.xml">ngx_http_js_module</link> module and specify the <link doc="../http/ngx_http_js_module.xml" id="js_import">js_import</link> directive with the <path>http.js</path> script file: <example> load_module modules/ngx_http_js_module.so; events {} http { js_import http.js; server { listen 8000; location / { js_content http.hello; } } } </example> </para> </listitem> </list> There is also a standalone <link doc="cli.xml">command line</link> utility that can be used independently of nginx for njs development and debugging. </para> </section> <section id="tested_os_and_platforms" name="Tested OS and platforms"> <para> <list type="bullet"> <listitem> FreeBSD / amd64; </listitem> <listitem> Linux / x86, amd64, arm64, ppc64el; </listitem> <listitem> Solaris 11 / amd64; </listitem> <listitem> macOS / x86_64; </listitem> </list> </para> </section> <section id="presentation" name="Presentation at nginx.conf 2018"> <para><video id="Jc_L6UffFOs" /></para> </section> </article>