Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow calls from localhost through Nginx Auth?

Tags:

nginx

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.

like image 504
Shrinath Avatar asked Dec 05 '25 01:12

Shrinath


1 Answers

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,

like image 198
Capilé Avatar answered Dec 08 '25 09:12

Capilé



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!