'nginx unknown directive "auth_jwt"
I want set jwt auth on my nginx but I got this error:
nginx: [emerg] unknown directive "auth_jwt" in /usr/local/etc/nginx/nginx.conf
I have nginx version: nginx/1.15.8 OS: macOs Mojave v10.14.2
I couldn't find the answer on Google or other websites.
/nginx.cofnig:
location / {
auth_jwt "closed site" token=$cookie_token;
auth_jwt_key_file conf/api_secret.jwk;
try_files $uri /index.html =404;
}
Solution 1:[1]
The original JWT module is part of Nginx Plus, but then there are many opensource free modules that do similar thing:
- https://github.com/tizpuppi/ngx_http_auth_jwt_module - supposed to be a drop-in replacement for ngx_http_auth_jwt_module from Nginx Plus (but currently became a bit outdated and lacks some features that the commercial module has), supports HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384 and ES512, can get token from
Authorization
header or from an Nginx variable, will respond withWWW-Authenticate
header if JWT validation failed, depends on Jansson & libjwt - https://github.com/TeslaGov/ngx-http-auth-jwt-module - supports HS256 and RS256, can get token from
Authorization
header or from a cookie with configurable name, can be configured to do 302 redirect to a login page if JWT validation failed, exposessub
andemailAddress
claims inX-UserId
andX-Email
headers respectively, easy to build a Docker image (based on centos 7), depends on Jansson & libjwt - https://github.com/max-lt/nginx-jwt-module - small Docker image (~16Mb) based on nginx-alpine, supports HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384 and ES512, can get token from
Authorization
header or from an Nginx variable, depends on Jansson & libjwt - https://github.com/ch1bo/nginx-jwt - supports HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384 and ES512, not only verifies the signature but can also issue signed JWT tokens, can get token from
Authorization
header with a fallback to cookie with same name (name of the cookie is not configurable), depends on Jansson & libjwt, doesn't have documentation - https://github.com/maxam18/nginx-ejwt-module - supports HS256 and RS256, can get token from
Authorization
header or from an Nginx variable, can extract and compare payload values with predefined values, will respond withWWW-Authenticate
header if JWT validation failed, no external dependencies - https://github.com/andrei-markeev/ngx_http_jwted_module - supports the modern Ed25519, can get token from
Authorization
header, exposes JWT claims json in $jwt_claims variable, no external dependencies
Despite a rather wide variety of open source modules, the commercial one from Nginx Plus has more features than any one of these modules, and is most likely much better battle-tested and also well maintained.
Disclaimer: I'm the author of the last module in this list.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |