Path: blob/main/xml/cn/docs/http/ngx_http_access_module.xml
1 views
<?xml version="1.0"?>12<!--3Copyright (C) Igor Sysoev4Copyright (C) Nginx, Inc.5-->67<!DOCTYPE module SYSTEM "../../../../dtd/module.dtd">89<module name="ngx_http_access_module模块"10link="/cn/docs/http/ngx_http_access_module.html"11lang="cn"12translator="WenMing"13rev="1">1415<section id="summary">1617<para>18模块 <literal>ngx_http_access_module</literal> 允许限制某些IP地址的客户端访问。19</para>2021<para>22也可以通过23<link doc="ngx_http_auth_basic_module.xml">密码</link>来限制访问。24使用25<link doc="ngx_http_core_module.xml" id="satisfy"/> 指令就能同时通过IP地址和密码来限制访问。26</para>2728</section>293031<section id="example" name="配置范例">3233<para>34<example>35location / {36deny 192.168.1.1;37allow 192.168.1.0/24;38allow 10.1.1.0/16;39allow 2001:0db8::/32;40deny all;41}42</example>43</para>4445<para>46规则按照顺序依次检测,直到匹配到第一条规则。47在这个例子里,IPv4的网络中只有48<literal>10.1.1.0/16</literal> 和 <literal>192.168.1.0/24</literal>允许访问,但49<literal>192.168.1.1</literal>除外,50对于IPv6的网络,只有<literal>2001:0db8::/32</literal>允许访问。51在规则很多的情况下,使用52<link doc="ngx_http_geo_module.xml">ngx_http_geo_module</link>53模块变量更合适。54</para>5556</section>575859<section id="directives" name="指令">6061<directive name="allow">62<syntax>63<value>address</value> |64<value>CIDR</value> |65<literal>all</literal></syntax>66<default/>67<context>http</context>68<context>server</context>69<context>location</context>70<context>limit_except</context>7172<para>73允许指定的网络地址访问。74</para>7576</directive>777879<directive name="deny">80<syntax>81<value>address</value> |82<value>CIDR</value> |83<literal>all</literal></syntax>84<default/>85<context>http</context>86<context>server</context>87<context>location</context>88<context>limit_except</context>8990<para>91拒绝指定的网络地址访问。92</para>9394</directive>9596</section>9798</module>99100101