redirect some IP addresses

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


Hello!

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 ~ "^(62.160.71.0/24)"){

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

    deny 62.160.71.0/24;

instead, see http://wiki.nginx.org/HttpAccessModule for details.  
Normally this will return 403 error, though this may be easily 
redefined with error_page directive (see 
http://wiki.nginx.org/HttpCoreModule#error_page).

If you do really need "if" testing instead of client addresses, 
use geo module (http://wiki.nginx.org/HttpGeoModule) for CIDR 
testing.

Maxim Dounin



More information about the nginx mailing list