JWT#

该模块使用指定的密钥验证 JSON Web Token (JWT)。 它与 Auth JWT 模块 不兼容

安装#

安装 该模块,请使用以下软件包之一:

  • Angie:angie-module-jwt

  • Angie PRO:angie-pro-module-jwt

加载模块#

main{} 上下文中启用该模块:

load_module modules/ngx_http_auth_jwt_module.so;

配置示例#

http {
    server {
        auth_jwt_key "0123456789abcdef" hex;
        auth_jwt     off;

        # Authorization via the Authentication header
        location /secured-by-auth-header/ {
            auth_jwt on;
        }

        # Authorization via cookie
        location /secured-by-cookie/ {
            auth_jwt $cookie_MyCookieName;
        }

        # Key inheritance and override
        location /secured-by-auth-header-too/ {
            auth_jwt_key "another-secret";
            auth_jwt on;
        }

        # Authorization via RSA key
        location /secured-by-rsa-key/ {
            auth_jwt_key /etc/keys/rsa-public.pem file;
            auth_jwt on;
        }

        location /not-secure/ {}
    }
}

其他信息#

详细文档和源代码,请参阅: max-lt/nginx-jwt-module