> For the complete documentation index, see [llms.txt](https://docshome.gitbook.io/nginx-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docshome.gitbook.io/nginx-docs/he-xin-gong-neng/http/ngx_http_access_module.md).

# ngx\_http\_access\_module

* [示例配置](/nginx-docs/he-xin-gong-neng/http/ngx_http_access_module.md#example_configuration)
* [指令](/nginx-docs/he-xin-gong-neng/http/ngx_http_access_module.md#directives)
  * [allow](/nginx-docs/he-xin-gong-neng/http/ngx_http_access_module.md#allow)
  * [deny](/nginx-docs/he-xin-gong-neng/http/ngx_http_access_module.md#deny)

`ngx_http_access_module` 模块允许限制对某些客户端地址的访问。

访问也可以通过[密码](/nginx-docs/he-xin-gong-neng/http/ngx_http_auth_basic_module.md)、[子请求结果](/nginx-docs/he-xin-gong-neng/http/ngx_http_auth_request_module.md)或 [JWT](/nginx-docs/he-xin-gong-neng/http/ngx_http_auth_jwt_module.md) 限制。可用 [satisfy](/nginx-docs/he-xin-gong-neng/http/ngx_http_core_module.md#satisfy) 指令通过地址和密码同时限制访问。

## 示例配置 <a href="#example_configuration" id="example_configuration"></a>

```
location / {
    deny  192.168.1.1;
    allow 192.168.1.0/24;
    allow 10.1.1.0/16;
    allow 2001:0db8::/32;
    deny  all;
}
```

按顺序检查规则，直到找到第一个匹配项。在本例中，仅允许 IPv4 网络 `10.1.1.0/16` 和 `192.168.1.0/24` 与 IPv6 网络 `2001:0db8::/ 32` 访问，不包括地址 `192.168.1.1`。在很多规则的情况下，最好使用 [ngx\_http\_geo\_module](/nginx-docs/he-xin-gong-neng/http/ngx_http_geo_module.md) 模块变量。

## 指令 <a href="#directives" id="directives"></a>

### allow

| -       | 说明                                                 |
| ------- | -------------------------------------------------- |
| **语法**  | **allow** `address` \| `CIDR` \| `unix:` \| `all`; |
| **默认**  | ——                                                 |
| **上下文** | http、server、location、limit\_except                 |

允许访问指定的网络或地址。如果指定了特殊值 `unix:`（1.5.1），则允许访问所有 UNIX 域套接字。

### deny

| -       | 说明                                                |
| ------- | ------------------------------------------------- |
| **语法**  | **deny** `address` \| `CIDR` \| `unix:` \| `all`; |
| **默认**  | ——                                                |
| **上下文** | http、server、location、limit\_except                |

拒绝指定网络或地址的访问。如果指定了特殊值 `unix:`（1.5.1），则拒绝所有 UNIX 域套接字的访问。

## 原文档

<http://nginx.org/en/docs/http/ngx_http_access_module.html>
