Shrinath
Shrinath

Reputation: 8118

How to allow calls from localhost through Nginx Auth?

I am using the following code :

location / {  
  satisfy any;  
  allow 127.0.0.1;  
  deny all;  
  auth_basic "closed site";  
  auth_basic_user_file conf/htpasswd;  
}

But when I do curl -I "http://mysite.com" it returns 401 :(
how do I allow localhost?

Edit :
The machine I am using this on is an amazon ec2 instance.

Ok,

I didn't realize that amazon ec2 instance will call its external/public IP when you call mysite.com :)

How silly.

So I am accepting @Capilé's answer for the hosts file workaround he mentioned.

Upvotes: 3

Views: 10458

Answers (1)

Capilé
Capilé

Reputation: 2088

It is correct, but probably mysite.com is not reaching the 127.0.0.1 interface of your server. If you try curl -I "http://127.0.0.1" (or any localhost aliases), you should get it.

Alternatively, you might add mysite.com to 127.0.0.1 through /etc/hosts (c:\windows\system32\drivers\etc\hosts on windows):

127.0.0.1  mysite.com

Cheers,

Upvotes: 5

Related Questions