How to set whitelist in Nginx through geo module

WBOY
Release: 2023-05-26 13:10:51
forward
1206 people have browsed it

Original configuration:

http {
......
Copy after login
Copy after login
limit_conn_zone $binary_remote_addr zone=one:10m;
limit_req_zone $binary_remote_addr zone=fifa:10m rate=5r/s;
Copy after login
......
server {
......
limit_conn one 5;
limit_req zone=fifa burst=100;
......
}}
Copy after login
Copy after login

Whitelist configuration:

http {
......
Copy after login
Copy after login
geo $whiteiplist {
 default 1;
 127.0.0.1 0;
 10.10.0.0/24 0;
}
map $whiteiplist $limit {
 1 $binary_remote_addr;
 0 "";
}
limit_conn_zone $limit zone=one:10m;
limit_req_zone $limit zone=fifa:10m rate=5r/s;
Copy after login
......
server {
......
limit_conn one 5;
limit_req zone=fifa burst=100;
......
}}
Copy after login
Copy after login

Description:

The geo directive defines a whitelist $whiteiplist, the default value is 1, all are restricted. If the client IP matches the IP listed in the whitelist, the $whiteiplist value is 0, which means it is not restricted.

The map command maps the $whiteiplist value to 1, which is the restricted IP, to the client IP. Map the $whiteiplist value of 0, which is the whitelist IP, to an empty string.

The limit_conn_zone and limit_req_zone instructions will be ignored for keys with null values, thereby achieving no limit on the listed IPs.

The above is the detailed content of How to set whitelist in Nginx through geo module. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template