1

I currently have an application I want accessible for everyone coming from 2 specifics IP address and protecting the same application via the same URL from user coming from another IP.

For example, I allow user having 190.190.190.110 and 190.190.190.112. And for other people I want Nginx refers to a htpassword file.

Does anyone know how to do it?

Edit: Quick Up

1

3 Answers 3

1

Try this:

   location / {
        satisfy any;

        allow 82.242.75.92;
        allow 82.242.75.98;
        deny all;

        auth_basic            "Restricted";
        auth_basic_user_file  /home/password_manager/passwords;
    }
1
  • Yeah, that's it. Tested and working.
    – minniux
    May 26, 2013 at 19:39
0

This is untested.. but something like this might work in your server block

server  {
  if ($remote_addr !~* "190.190.190.[110|112]") {
     auth_basic            "Restricted";
     auth_basic_user_file  /path/to/htpasswd.file;
  }
}

my regular expression might be wrong but that is the jist of how to do it.

1
  • [emerg] "auth_basic" directive is not allowed here
    – user956584
    Aug 3, 2016 at 12:20
0

I don't think that you can restrict basic-auth based on IP directly, but you can force a redirect to a separate site (i.e. new server-block) that does.

Check this out:

Use Nginx to server different pages depending on IP address/subnet

(I need to run and implement this myself...)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .