Nginx 如何禁用每个 IP 速率限制

Nginx 如何禁用每个 IP 速率限制

我有一个 API,它通过 EC2 服务器的私有 IP 连接并执行一系列回调。我想在此场景中禁用每个 IP 的速率限制。我在 Nginx 文档中尝试过这种方法。

这并没有解决速率限制问题。访问日志

192.168.192.51 - - [14/Jun/2021:00:09:55 +0530] "POST /project/api/v1/vendor/callback HTTP/1.1" 429 8576 "-" "Java/1.8.0_151" "-" "192.168.13.173" sn="192.168.13.173" rt=0.009 ua="unix:/var/run/php/php7.4-fpm.sock" us="429" ut="0.008" ul="8591" cs=-

Nginx 配置文件

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 1024;
    # multi_accept on;
}

http {

    geo $limit {
        default 1;
        192.168.192.51 0;
    }
 
    map $limit $limit_key {
            0 "";
            1 $binary_remote_addr;
    }
 
    limit_req_zone $limit_key zone=req_zone:10m rate=100r/s;

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    error_log /var/log/nginx/error.log warn;
    log_format main_ext '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" ' '"$host" sn="$server_name" ' 'rt=$request_time ' 'ua="$upstream_addr" us="$upstream_status" ' 'ut="$upstream_response_time" ul="$upstream_response_length" ' 'cs=$upstream_cache_status' ;
    access_log /var/log/nginx/access.log main_ext;

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

    fastcgi_buffers 8 16k;
        fastcgi_buffer_size 32k;
        fastcgi_connect_timeout 90;
        fastcgi_send_timeout 90;
        fastcgi_read_timeout 90;
}

服务器块

server {
    listen 80;
    listen 81;

        root /data/www;

        index index.html index.htm index.php;

        server_name 192.168.13.173;


        location / {
                try_files $uri $uri/ /index.php$is_args$args;
        }

    location /project{
                alias /data/www/project/public;
                try_files $uri $uri/ @project;

                location ~ \.php$ {
                        include snippets/fastcgi-php.conf;
                        fastcgi_param SCRIPT_FILENAME $request_filename;
                        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
                }
        }

        location @project {
                rewrite /project/(.*)$ /project/index.php?/$1 last;
        }


    location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }


}

相关内容