Limit_req is limiting requests outside of location block it is applied to

I have a location ~* .php$ with limit_req set inside it. But requests
outside of this location block, e.g. for .js and .css files are also
being
limited. I only want to limit the number of requests to .php files.

This is my config:

worker_processes 2;

pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

server_names_hash_bucket_size 128;

sendfile on;
keepalive_timeout 10 10;

port_in_redirect off;

#Fix IP address
set_real_ip_from 127.0.0.1;
real_ip_header X-Forwarded-For;

limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

log_format main '$remote_addr - $remote_user [$time_local] ’
'“$request” $status $body_bytes_sent “$http_referer” ’
‘“$http_user_agent”’;

server {
listen 7776;
server_name www.test.com;
access_log logs/test.log main;
error_log logs/test-error.log warn;
root /path/to/test.com;

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

Pass PHP scripts on to PHP-FPM

location ~* .php$ {
limit_req zone=one burst=5;
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/path/to/php.sock;
}
}
}

Posted at Nginx Forum:

Never mind, Nginx was actually limiting requests correctly.

What I was seeing in my logs was requests for non-existent .js and .css
files, which were then being passed to index.php as per my try_files in
the
/ location block.

Posted at Nginx Forum: