<!-- review: finished -->

<a id="external-jwt"></a>

# JWT

该模块使用指定的密钥验证 JSON Web Token (JWT)。
它与 [Auth JWT](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt) 模块 **不兼容**。

<a id="installation-14"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-jwt`
- Angie PRO:`angie-pro-module-jwt`

<a id="loading-the-module-14"></a>

## 加载模块

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

```nginx
load_module modules/ngx_http_auth_jwt_module.so;
```

<a id="configuration-example-91"></a>

## 配置示例

```nginx
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/ {}
    }
}
```

<a id="additional-information-15"></a>

## 其他信息

详细文档和源代码,请参阅:
[https://github.com/max-lt/nginx-jwt-module](https://github.com/max-lt/nginx-jwt-module)
