redirect some IP addresses

Maxim Dounin mdounin at
Wed Jun 29 09:29:16 MSD 2011


On Wed, Jun 29, 2011 at 01:11:38AM -0400, Jiff wrote:

> Hi forumers,
> As I can't test it, I'd like to know if my redirect code is correct or
> not:
> location / {
>             if ($remote_addr ~ "^("){

No, this is clearly incorrect and won't work.  Use


instead, see for details.  
Normally this will return 403 error, though this may be easily 
redefined with error_page directive (see

If you do really need "if" testing instead of client addresses, 
use geo module ( for CIDR 

Maxim Dounin

More information about the nginx mailing list