JWT#

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

加载模块#

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

load_module modules/ngx_http_auth_jwt_module.so;

配置示例#

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

        # 通过 Authentication 头部认证
        location /secured-by-auth-header/ {
            auth_jwt on;
        }

        # 通过 cookie 进行认证
        location /secured-by-cookie/ {
            auth_jwt $cookie_MyCookieName;
        }

        # 继承和重写密钥
        location /secured-by-auth-header-too/ {
            auth_jwt_key "another-secret";
            auth_jwt on;
        }

        # 通过 RSA 密钥认证
        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