# Limit\_req is limiting requests outside of location block it is applied to

**URL:** <https://www.ruby-forum.com/t/limit-req-is-limiting-requests-outside-of-location-block-it-is-applied-to/244253>\
**Category:** NGINX\
**Created:** [March 11, 2016, 1:33pm UTC](https://www.ruby-forum.com/t/limit-req-is-limiting-requests-outside-of-location-block-it-is-applied-to/244253 "2016-03-11T13:33:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [March 11, 2016, 1:33pm UTC](https://www.ruby-forum.com/t/limit-req-is-limiting-requests-outside-of-location-block-it-is-applied-to/244253/1 "2016-03-11T13:33:15Z")

</div>

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](http://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:

> **[limit\_req is limiting requests outside of location block it is applied to](https://forum.nginx.org/read.php?2,265244,265244#msg-265244)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![djeyewater](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/71e660/32.png) [@djeyewater](https://www.ruby-forum.com/u/djeyewater)\
**Post date:** [March 11, 2016, 2:17pm UTC](https://www.ruby-forum.com/t/limit-req-is-limiting-requests-outside-of-location-block-it-is-applied-to/244253/2 "2016-03-11T14:17:39Z")

</div>

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:

> **[Re: limit\_req is limiting requests outside of location block it is applied to](https://forum.nginx.org/read.php?2,265244,265248#msg-265248)**
>
> 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...
