Welcome! Log In Create A New Profile

Advanced

Re: How to limit_req depending if the requests has a REFERER or not.

Valentin V. Bartenev
June 06, 2012 03:16AM
On Wednesday 06 June 2012 03:31:03 Valentin V. Bartenev wrote:
> On Wednesday 06 June 2012 02:33:09 Joseph Cabezas wrote:
> > I have something like this... I need to be able to apply three different
> > limit_req depending:
> >
> > a.) If the referer to click.php is domain.com ... apply zone1
> > b.) If there is some other referer apply zone2 on click.php
> > c.) If there is no referer apply zone3 on click.php
> >
> > location /click.php { limit_req zone=one; proxy_pass http://backend; }
[...]
>
> map $invalid_referer $zone1 {
> 0 1;
> 1 '';
> }
>
> map $invalid_referer $zone2 {
> 0 '';
> 1 $is_referer;
> }
>
> map $invalid_referer $zone3 {
> 0 '';
> 1 $no_referer;
> }
[...]

Oops, Ruslan Ermilov pointed out to me that the "false" value of
$invalid_referer is an empty string, not "0".

http://nginx.org/r/valid_referers

Well, then the correct config example is as follows:

http {

map $http_referer $zone3 {
default 1;
~^. '';
}

map $zone3 $zone2 {
default $invalid_referer;
1 '';
}

map $invalid_referer $zone1 {
default 1;
1 '';
}

limit_req_zone $zone1 zone=zone1:128k rate=50r/s;
limit_req_zone $zone2 zone=zone2:128k rate=10r/s;
limit_req_zone $zone3 zone=zone3:128k rate=3r/s;

server {
valid_referers domain.com;

location /click.php {
limit_req zone=zone3 burst=12;
limit_req zone=zone2 burst=10 nodelay;
limit_req zone=zone1 burst=100 nodelay;
...

wbr, Valentin V. Bartenev

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

How to limit_req depending if the requests has a REFERER or not.

Joseph Cabezas June 05, 2012 06:34PM

Re: How to limit_req depending if the requests has a REFERER or not.

Valentin V. Bartenev June 05, 2012 07:32PM

Re: How to limit_req depending if the requests has a REFERER or not.

Valentin V. Bartenev June 06, 2012 03:16AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 148
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready