NGINX limit_except is not woking

Viewed 15

I Tested NGINX Config with API Access ( With Method Except )

# NGINX IP Is 10.250.11.16 

log_format  20004  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for" '
                  '"$bytes_sent" "$request_length" "$request_time" '
                  '"$gzip_ratio" $server_protocol ';

server {
    satisfy all;
    listen 20004;
    status_zone server_APIAccess_MethodDeny_NGINXapi_20004;
    include /etc/nginx/api_conf.d/api_error.conf;
    error_page 404 = @400;         # Invalid paths are treated as bad requests
    proxy_intercept_errors on;     # Do not send backend errors to the client
    default_type application/json; # If no content-type then assume JSON

    location / {
        limit_except GET { 
            allow 10.250.11.16/32;
            allow 10.250.20.137/32;
            deny all;                            
        }
        add_header X-IP "$remote_addr" always;  # Tested Header 
        add_header X-Method "$request" always;  # Tested Header 
        access_log /var/log/nginx/access.log 20004;
        error_log /var/log/nginx/debug.log debug;       

        proxy_pass http://10.250.11.11/api/7/nginx;
        
    }
   
}

All IP Is Allow GET Method ( ex : Client IP - 10.250.11.12 / Request URL : curl -X GET 10.250.11.16:20004 )

  • Access Log IP showing 10.250.11.12 Client IP and 200 Return Code Checked
1 Answers

It's working as expected. According to nginx docs, limit_except GET will limit all methods except GET and HEAD, so it's expected that all ips would work.

Related