Example of setting up a whitelist in Nginx using the geo module

Example of setting up a whitelist in Nginx using the geo module

Original configuration:

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

Whitelist configuration:

http {
......
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;
......
server {
......
limit_conn one 5;
limit_req zone=fifa burst=100;
......
}}

illustrate:

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

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

Limit_conn_zone and limit_req_zone directives with empty keys will be ignored, so there is no limit on the listed IPs.

The above example of Nginx setting whitelist through geo module is all I want to share with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • How to set directory whitelist and IP whitelist in nginx
  • How to dynamically add access whitelist to nginx
  • Configure a firewall with blacklist or whitelist function for the Nginx server
  • Detailed explanation of nginx-naxsi whitelist rules

<<:  JS realizes simple picture carousel effect

>>:  Mysql solution to improve the efficiency of copying large data tables

Recommend

Mysql implementation of full-text search and keyword scoring method example

1. Introduction Today a colleague asked me how to...

Teach you the detailed process of installing DOClever with Docker Compose

Table of contents 1. What is Docker Compose and h...

Native JS implements a very good-looking counter

Today I will share with you a good-looking counte...

Implementation of CSS3 button border animation

First look at the effect: html <a href="#...

MySQL 5.7.15 version installation and configuration method graphic tutorial

This article shares with you a detailed tutorial ...

Box-shadow and drop-shadow to achieve irregular projection example code

When we want to add a shadow to a rectangle or ot...

How to use Vue to implement CSS transitions and animations

Table of contents 1. The difference between trans...

Summary of three rules for React state management

Table of contents Preface No.1 A focus No.2 Extra...

Element uses scripts to automatically build new components

Table of contents background How does element-ui&...

MySQL permission control detailed explanation

Table of contents mysql permission control Permis...

Implementation of effective user groups and initial user groups in Linux

First check the /etc/group file: [root@localhost ...