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

How to use Docker-compose to deploy Django applications offline

Table of contents Install Docker-ce for the devel...

Sample code for testing technology application based on Docker+Selenium Grid

Introduction to Selenium Grid Although some new f...

Collection of 25 fonts used in famous website logos

This article collects the fonts used in the logos...

How to notify users of crontab execution results by email

symptom I set a crontab task on a centos7 host, b...

Analysis of the process of implementing Nginx+Tomcat cluster under Windwos

Introduction: Nginx (pronounced the same as engin...

CocosCreator classic entry project flappybird

Table of contents Development Environment Game en...

Summary of methods for cleaning Mysql general_log

Method 1: SET GLOBAL general_log = 'OFF';...

Implementation of automatic completion of Docker commands

Preface I don't know how long this friend has...

CSS3 transition to implement notification message carousel

Vue version, copy it to the file and use it <t...

MySQL 8.0.22 decompression version installation tutorial (for beginners only)

Table of contents 1. Resource download 2. Unzip t...

HTML iframe usage summary collection

Detailed Analysis of Iframe Usage <iframe frame...

How to use Nginx to prevent IP addresses from being maliciously resolved

Purpose of using Nginx Using Alibaba Cloud ECS cl...