I'm trying to redirect some users to another website based on their client IP address. For example if user is in range they'd be redirected to another website.

I've found this article which mentions this method:

server {
   if ($remote_addr = {   ## Also will it work with subnet address like
      rewrite ^ http://www.yourwebsite.com/otherpage.htm;

I guess it would work fine. But how can I supply IP range list file into this if block? Including hundreds of IP address in single line wouldn't look good.

  • P.S: I don't have that geo module installed nor don't want to break production system. Looks like geo module is not installed by default on my nginx. Edit: I've --with-http_geoip_module. Is it that geo module everybody talking about? – Shinebayar G Oct 23 '19 at 9:01
  • Obviously check it on a non-productive-server first...but either the geo module or some intricate regex. It's what the module is for! – Lenniey Oct 23 '19 at 9:21

Browse other questions tagged or ask your own question.