Sign up ×
Server Fault is a question and answer site for 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 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

3 Answers 3

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.