> 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/stream/ngx_stream_access_module.md).

# ngx\_stream\_access\_module

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

`ngx_stream_access_module` 模块（1.9.2）允许对某些客户端地址限制访问。

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

```
server {
    ...
    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`（不包括地址 `192.168.1.1`）和 IPv6 网络`2001:0db8::/32` 进行访问。

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

### allow

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

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

### deny

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

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

## 原文档

<http://nginx.org/en/docs/stream/ngx_stream_access_module.html>
