Need help with ngx-http-auth-jwt-module?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

137 Stars 62 Forks MIT License 121 Commits 7 Opened issues


Secure your NGINX locations with JWT

Services available


Need anything else?

Contributors list


This is an NGINX module to check for a valid JWT and proxy to an upstream server or redirect to a login page.

Building and testing

To build the Docker image, start NGINX, and run our Bash test against it, run


When you make a change to the module, run

make rebuild-nginx

When you make a change to
, run
make rebuild-test-runner

| Command | Description | | -------------------------- |:-------------------------------------------:| |

make build-nginx
| Builds the NGINX image | |
make rebuild-nginx
| Re-builds the NGINX image | |
make build-test-runner
| Builds the image that will run
| |
make rebuild-test-runner
| Re-builds the image that will run
| |
make start-nginx
| Starts the NGINX container | |
make stop-nginx
| Stops the NGINX container | |
make test
| Runs
against the NGINX container |

You can re-run tests as many times as you like while NGINX is up. When you're done running tests, make sure to stop the NGINX container.

The Dockerfile builds all of the dependencies as well as the module, downloads a binary version of NGINX, and runs the module as a dynamic module.

Tests get executed in containers. This project is 100% Docker-ized.


This module depends on the JWT C Library

Transitively, that library depends on a JSON Parser called Jansson as well as the OpenSSL library.

NGINX Directives

This module requires several new

directives, which can be specified in on the
auth_jwt_key "00112233445566778899AABBCCDDEEFF00112233445566778899AABBCCDDEEFF"; # see docs for format based on algorithm
auth_jwt_loginurl "";
auth_jwt_enabled on;
auth_jwt_algorithm HS256; # or RS256
auth_jwt_validate_email on;  # or off

The default algorithm is 'HS256', for symmetric key validation. When using HS256, the value for

should be specified in binhex format. It is recommended to use at least 256 bits of data (32 pairs of hex characters or 64 characters in total) as in the example above. Note that using more than 512 bits will not increase the security. For key guidelines please see NIST Special Publication 800-107 Recommendation for Applications Using Approved Hash Algorithms, Section 5.3.2 The HMAC Key.

The configuration also supports the

'RS256', for RSA 256-bit public key validation. If using "authjwtalgorithm RS256;", then the
field must be set to your public key. That is the public key, rather than a PEM certificate. I.e.:
auth_jwt_key "-----BEGIN PUBLIC KEY-----
-----END PUBLIC KEY-----";

A typical use would be to specify the key and loginurl on the main level and then only turn on the locations that you want to secure (not the login page). Unauthorized requests are given 302 "Moved Temporarily" responses with a location of the specified loginurl.

auth_jwt_redirect            off;

If you prefer to return 401 Unauthorized, you may turn

auth_jwt_validation_type AUTHORIZATION;
auth_jwt_validation_type COOKIE=rampartjwt;

By default the authorization header is used to provide a JWT for validation. However, you may use the

configuration to specify the name of a cookie that provides the JWT.
auth_jwt_validate_email off;

By default, the module will attempt to validate the email address field of the JWT, then set the x-email header of the session, and will log an error if it isn't found. To disable this behavior, for instance if you are using a different user identifier property such as 'sub', set

to the value

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.