These modules are all compiled into Nginx by default unless a module is manually specified to be excluded in configure.
This module provides a simple host-based http://www.aliyun.com/zixun/aggregation/38609.html "> access control."
Nginx_http_access_module This module can be accessed by checking client IP for access control.
Control rules are checked in the order they are declared, and the first matching IP access rule is enabled.
The following example:
Location/{deny 192.168.1.1; allow 192.168.1.0/24; allow 10.1.1.0/16; deny all;}
The above example allows only 192.168.1.0/24 and 10.1.1.0/16 network segments to access this location field, but 192.168.1.1 is an exception.
Note the order of the rules, if you have used Apache you may think you can control the order of the rules and they can work properly, but in practice, the following example will reject all connections:
Location/{#这里将永远输出403错误. Deny all; #这些指令不会被启用 because the arriving connection was already rejected in the first one deny 192.168.1.1; Allow 192.168.1.0/24; Allow 10.1.1.0/1}
If you want to implement a number of complex rules, it is best to use GEOIP module modules.
Instructions
Allow
Syntax: Allow [address | CIDR | ALL]
Default value: No
Working with fields: HTTP, server, location, limit_except
Variables: None
directive specifies the IP or network segment that is allowed to access.
Deny
Syntax: Deny [address | CIDR | ALL]
Default value: No
Working with fields: HTTP, server, location, limit_except
Variables: None
directive specifies an IP or network segment that is denied access.
Tips and Tricks
The Httpaccess module can be used with the error_page instruction to redirect an unauthenticated access request.
Error_page 403 http://example.com/forbidden.html;location/{deny 192.168.1.1; allow 192.168.1.0/24; allow 10.1.1.0/16; Deny all;}