njs is a subset of the JavaScript language that allows extending nginx functionality. njs is created in compliance with ECMAScript 5.1 (strict mode) with some ECMAScript 6 and later extensions.
Questions tagged [njs]
22 questions
2
votes
0 answers
module not added after configure with --add-module
I have a dockerfile
FROM ubuntu:latest
RUN apt-get update
RUN apt-get -y install wget
RUN wget 'http://nginx.org/download/nginx-1.21.6.tar.gz'
RUN tar -xzvf nginx-1.21.6.tar.gz
RUN apt-get install -y git
RUN apt-get install -y gcc
RUN apt-get…

Danil Giniyatullin
- 43
- 5
2
votes
1 answer
Is there a way to access nginx.var in javascript
I have some nginx variables defied in my server_content.conf file is there a way we can access it in my .js file?
servercontent.conf
...
set $debug_log 'off';
...
logging.js
if(ngx.var.debug_log = 'on')
.. do something

Aman
- 21
- 4
2
votes
1 answer
How to pass variable value from js file to nginx config with njs module
I am trying to use njs to have chain request with nginx njs, i have below issue
here is my javascript file and my scenario is
I have two of API.
I want to request first api and get it's reponse then append first api's response (cloud be JSON…

behrooz razzaghi
- 105
- 1
- 1
- 8
2
votes
1 answer
How can I decrypt aes256 encrypted string using njs?
sha 256 Encrypt code (from document)
function hmacEncrypt(r) {
let str = r.uri.split("/", 2)
return require('crypto').createHash('sha256', 'key')
.update(str)
.digest('base64url');
}
I…

Rightly
- 31
- 2
2
votes
1 answer
Extend nginx via nodejs, njs script language
I found a section on the nginx docs that you can use
ECMAScript 5.1 (strict mode) with some ECMAScript 6 and later extensions
to extend nginx. As use case
Complex access control and security checks in njs before a request reaches an upstream…

Marc
- 2,920
- 3
- 14
- 30
1
vote
1 answer
extract qcstatement from eidas in nginx
we are working on extracting qcstatement from an eIDAS certificate which is send as a incoming request to nginx. I have found that nginx java script njs module is native to nginx and can be used for scripting.
our requirement would be that the raw…

Charandeep Singh
- 31
- 1
- 2
1
vote
0 answers
Is it possible to use libsquoosh (img processing Node library) in Nginx njs eniroment
I am trying:
to use libsquoosh with Nginx njs scripting module for some fancy on-the-fly image cashing\processing for the internal OSM tile server.
To use Node libraries in the njs environment I am trying to follow Nginx how-to,
But can't seem to go…

Павел Пешеев
- 90
- 8
1
vote
1 answer
Nginx does not return response body when using js_body_filter njs directive
The problem is that when using js_body_filter directive nginx does not return response. In fact this is sample code which can be found in docs and examples. What am I missing?
Below all configuration together with Dockerfile on which this can be…

lbednaszynski
- 678
- 2
- 12
- 24
1
vote
2 answers
nginx javascript module persistence
Is it possible to persist some data in the javascript module of nginx?
I need to safe some data from the request to validate if the following requests are allowed.

Oliver Stahl
- 617
- 3
- 19
0
votes
0 answers
Conditional auth_request in Nginx
I need to add conditional authorization to a redirection in Nginx, only when one defined url parameter is received (t in this case). And the value of this parameter has to be passed to the authentication server as a Bearer token in the Authorization…

chmp
- 16
- 2
0
votes
0 answers
I am not able to access host machine from njs script nginx ser is hosted on docker client
I have tried with host.docker.internal and it works fine inside default.conf. However if I use it inside njs script file (using js-content) it is not working.
Here is my default.config file and njs script file:
server {
listen 80;
…

Gourango Ghosh
- 40
- 8
0
votes
0 answers
mtls and jwt authentication flow scenario NGINX as an API Gateway?
I have a scenario where mTLS authentication between a B2B (client) and NGINX API gateway is required on one side of the auth flow to access a resource from an API endpoint (behind the nginx api gateway) and JWT authorization is required between the…

Traiano Welcome
- 783
- 2
- 12
- 24
0
votes
0 answers
execute njs script before proxy_pass
I am configuring à nginx location but I need to run a script that update requestBody before redirection :
This my conf but when i deploy it still redirect without update requestBody or return error
Parent nginx.conf:
// .....
js_import…

AmenzO
- 409
- 7
- 19
0
votes
0 answers
Nginx proxy_pass: put response body into cookie
totally new to nginx, I am trying to implement some oauth2 web flow:
client ask for login,
the nginx I am using as reverse proxy redirects to authentication provider,
nginx proxyies the callback to auth provider getting the auth token with the…

Francesco
- 1,742
- 5
- 44
- 78
0
votes
0 answers
r.requestBody/r.requestText/r.requestBuffer is undefined (NJS - JavaScript Modules on NGINX)
I'm building a NGINX module with JavaScript, that read incoming requests and design whether to pass them to the proxy server, or to ignore them and return a "block.html" page as a response [kinda WAF].
The problem is when I try to access…

NO NAME
- 1
- 1