Mercurial > hg > nginx-site
view xml/en/docs/njs/index.xml @ 2257:8cef5ef98336
Changed quotes to ASCII in NJS example.
author | Nick Shadrin <nick@nginx.com> |
---|---|
date | Wed, 17 Oct 2018 15:42:16 -0700 |
parents | 32ba43abf9cd |
children | 1bec6f727a84 |
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="26" toc="no"> <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 doc="examples.xml"/> </listitem> <listitem> <link doc="compatibility.xml"/> </listitem> <listitem> <link doc="cli.xml"/> </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> </section> <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="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 doc="examples.xml">examples</link> and <link url="https://www.nginx.com/blog/tag/nginscript/">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>hello_world.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!"); } </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_include">js_include</link> directive with the <path>hello_world.js</path> script file: <example> load_module modules/ngx_http_js_module.so; events {} http { js_include hello_world.js; server { listen 8000; location / { js_content 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> </article>