cookie and source IP logic in server block

sfrazer nginx-forum at
Mon Oct 14 22:16:14 UTC 2013


I'm trying to block certain IP ranges at my nginx server, but would like to
offer the ability to bypass the block by completing a back-end CAPTCHA,
which would set a cookie.

Currently I set the block like so:

geo $remote_addr $blocked {
default 0;
include /etc/nginx/conf/nginx-blocked-ips.conf;


recursive_error_pages on;
error_page 429 = @banned;
if ($blocked = 1) {
return 429;

location @banned {
set $args "";
rewrite ^ /banned/ ;

Since I can't nest "if" statements and I can't make a compound check using
"&&" or "||" or something similar, how can I check both the blocked variable
and look to see if a cookie is set?

Posted at Nginx Forum:,243687,243687#msg-243687

More information about the nginx mailing list