Hello,
I’m glad to announce a new release of NGINX JavaScript module (njs).
This release focuses on extending http and stream modules.
Notable new features:
- js_import directive.
: nginx.conf:
: js_import foo.js;
: js_import lib from path/file.js;
:
: location / {
: js_content foo.bar;
: }
:
: foo.js:
: function bar(r) {
: r.return(200);
: }
:
: export default {bar};
- multi-value headers support in r.headersOut:
: foo.js:
: function content(r) {
: r.headersOut[‘Set-Cookie’] = [
: ‘foo=111; Max-Age=3600; path=/’,
: ‘bar=qqq; Max-Age=86400; path=/’
: ];
:
: r.return(200);
: }
You can learn more about njs:
- Overview and introduction: http://nginx.org/en/docs/njs/
- Presentation: https://youtu.be/Jc_L6UffFOs
- Using node modules with njs: http://nginx.org/en/docs/njs/node_modules.html
Feel free to try it and give us feedback on:
- Github: https://github.com/nginx/njs/issues
- Mailing list: http://mailman.nginx.org/mailman/listinfo/nginx-devel
Changes with njs 0.4.0 23 Apr 2020
nginx modules:
*) Feature: added js_import directive.
*) Feature: added support for multi-value headers in r.headersOut.
*) Improvement: iteration over r.headersOut with special headers.
*) Improvement: iteration over r.headersOut with duplicates.
*) Change: r.responseBody property handler now returns “undefined”
instead of throwing an exception if response body is not available.
Core:
*) Feature: added script arguments support in CLI.
*) Feature: converting externals values to native js objects.
*) Bugfix: fixed NULL-pointer dereference in “__proto__” property
handler.
*) Bugfix: fixed handling of no-newline at the end of the script.
*) Bugfix: fixed RegExp() constructor with empty pattern and
non-empty flags.
*) Bugfix: fixed String.prototype.replace() when function
returns non-string.
*) Bugfix: fixed reading of pseudofiles in “fs”.
Hi,
I'm glad to announce a new release of NGINX Unit.
In addition to improved stability, this release introduces two handy features.
The first one is configured using the "return" and "location" options of the
action object. It can be used to immediately generate a simple HTTP response
with an arbitrary status - for example, to deny access to some resources:
{
"match": {
"uri": "*/.git/*"
},
"action": {
"return": 403
}
}
Or, you can redirect a client to another resource:
{
"match": {
"host": "example.org",
},
"action": {
"return": 301,
"location": "http://www.example.org"
}
}
See the documentation for a detailed description of routing:
- https://unit.nginx.org/configuration/#routes
The second new feature of the release is mostly syntax sugar rather than new
functionality. Now, you can specify servers' weights in an upstream group
using fractional numbers.
Say, you have a bunch of servers and want one of them to receive half as many
requests as the others for some reason. Previously, the only way to achieve
that was to double the weights of all the other servers:
{
"192.168.0.101:8080": {
"weight": 2
},
"192.168.0.102:8080": {
"weight": 2
},
"192.168.0.103:8080": { },
"192.168.0.104:8080": {
"weight": 2
}
}
Using fractional weights, you can perform the update much easier by altering
the weight of the server in question:
{
"192.168.0.101:8080": { },
"192.168.0.102:8080": { },
"192.168.0.103:8080": {
"weight": 0.5
},
"192.168.0.104:8080": { }
}
For details of server groups, see here:
- https://unit.nginx.org/configuration/#upstreams
Changes with Unit 1.17.0 16 Apr 2020
*) Feature: a "return" action with optional "location" for immediate
responses and external redirection.
*) Feature: fractional weights support for upstream servers.
*) Bugfix: accidental 502 "Bad Gateway" errors might have occurred in
applications under high load.
*) Bugfix: memory leak in the router; the bug had appeared in 1.13.0.
*) Bugfix: segmentation fault might have occurred in the router process
when reaching open connections limit.
*) Bugfix: "close() failed (9: Bad file descriptor)" alerts might have
appeared in the log while processing large request bodies; the bug
had appeared in 1.16.0.
*) Bugfix: existing application processes didn't reopen the log file.
*) Bugfix: incompatibility with some Node.js applications.
*) Bugfix: broken build on DragonFly BSD; the bug had appeared in
1.16.0.
Please also see a blog post about the new features of our two previous releases:
- https://www.nginx.com/blog/nginx-unit-1-16-0-now-available/
To keep the finger on the pulse, refer to our further plans in the roadmap here:
- https://github.com/orgs/nginx/projects/1
Stay healthy, stay home!
wbr, Valentin V. Bartenev