Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 and And for other people I want Nginx refers to a htpassword file.

Does anyone know how to do it?

Edit: Quick Up

share|improve this question

migrated from Sep 15 '11 at 10:38

This question came from our site for professional and enthusiast programmers.

See this question:… – Alexander Azarov Sep 15 '11 at 14:24

Try this:

   location / {
        satisfy any;

        deny all;

        auth_basic            "Restricted";
        auth_basic_user_file  /home/password_manager/passwords;
share|improve this answer
Yeah, that's it. Tested and working. – minniux May 26 '13 at 19:39

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.

share|improve this answer

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...)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.