Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I got a problem with NGINX limit_req_zone. Anyone can help? The problem is that, I want to limit user access to some specific URL, for example:

/forum.php?mod=forumdisplay? /forum.php?mod=viewthread&***

But, I do want to add an exception for below URL,

/forum.php?mod=image&*

Below is the location section of my configuration, the problem is that, for URL started with /forum.php?mod=image&*, the limitation is still applied.
Any body can help?

location ~*^/forum.php?mod=image$ {
    root           /web/www;
    fastcgi_pass   unix:/tmp/nginx.socket;
    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    include        fastcgi_params;
    }
location ~*^/(home|forum|portal).php$ {
    root           /web/www;
    limit_conn   addr  5;
    limit_req zone=refresh burst=5 nodelay;
    fastcgi_pass   unix:/tmp/nginx.socket;
    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    include        fastcgi_params;
    }
location ~ \.php$ {
    root           /web/www;
    fastcgi_pass   unix:/tmp/nginx.socket;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    include        fastcgi_params;
    }
share|improve this question
    
?mod=image is a GET parameter. It isn't part of URI, that matched by locations. –  VBart Jul 19 '12 at 18:37

1 Answer 1

map $arg_mod $forum_limit {
    default  $binary_remote_addr;
    image    '';
}

limit_conn_zone $forum_limit zone=forum_conn:10m;
limit_req_zone $forum_limit zone=forum_req:10m rate=1r/s;

server {

    root /web/www;

    location ~ ^/(?:home|forum|portal)\.php$ {

        limit_conn forum_conn 5;
        limit_req zone=forum_req burst=5 nodelay;

        fastcgi_pass   unix:/tmp/nginx.socket;
        fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ \.php$ {
        fastcgi_pass   unix:/tmp/nginx.socket;
        fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
    }
}
share|improve this answer
    
Thanks Vbart. But I'm not understand your settings. Why you are using ~ ^/(?:home|forum|portal)\.php$ , and what's the map part used for? –  Meteor Jul 20 '12 at 9:14
    
I’ve tested this code, it's not work –  Meteor Jul 20 '12 at 13:46
    
How do you test it? –  VBart Jul 20 '12 at 14:11
    
map used to disable limit_req and limit_conn if a request has argument mod=image. In this case it set $forum_limit to empty value and the limits do not apply. –  VBart Jul 20 '12 at 14:17
    
I use ~ ^/(?:home|forum|portal)\.php$ because you did. –  VBart Jul 20 '12 at 14:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.