Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
1  
See this question: serverfault.com/questions/267611/… –  Alexander Azarov Sep 15 '11 at 14:24
add comment

migrated from stackoverflow.com Sep 15 '11 at 10:38

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

3 Answers

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
add comment

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
add comment

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;
    }
share|improve this answer
    
Yeah, that's it. Tested and working. –  minniux May 26 '13 at 19:39
add comment

Your Answer

 
discard

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.