# Simple http authentication not working

**URL:** <https://www.ruby-forum.com/t/simple-http-authentication-not-working/207899>\
**Category:** NGINX\
**Created:** [June 5, 2011, 10:23pm UTC](https://www.ruby-forum.com/t/simple-http-authentication-not-working/207899 "2011-06-05T22:23:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [June 5, 2011, 10:23pm UTC](https://www.ruby-forum.com/t/simple-http-authentication-not-working/207899/1 "2011-06-05T22:23:15Z")

</div>

Below is my config. The folder /site/private is supposed to show the  
usual HTTP authentication box, but the php files from that folder just  
start downloading in clear text. What am I doing wrong? The path of the  
passwd file is correct.

Thanks for any pointers!

location / {

```
  location

```

~.\*.(gif|jpg|png|ico|swf|rss|xml|htm|txt|js|css|gz|doc|xls|pdf)$ {  
expires max;  
try\_files $uri @backend;  
log\_not\_found off;  
}

```
  location /site/private {
    auth_basic "Restricted";
    auth_basic_user_file

```

/home/MYDOMAIN/.htpasswds/public\_html/www/private/passwd;  
}

```
  proxy_pass http://MY.IP.IS.HERE:8081;
  include proxy.inc;
} #-- End of root location

location @backend {
  internal;
  proxy_pass http://MY.IP.IS.HERE:8081;
  include proxy.inc;
}

```

Posted at Nginx Forum:

> **[Simple http authentication not working](https://forum.nginx.org/read.php?2,204172,204172#msg-204172)**
>
> Below is my config. The folder /site/private is supposed to show the usual HTTP authentication box, but the php files from that folder just start downloading in clear text. What am I doing wrong? The path of the passwd file is correct. Thanks for any...

---

<div class="post-metadata">

**Author:** ![pk899](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@pk899](https://www.ruby-forum.com/u/pk899)\
**Post date:** [June 5, 2011, 11:44pm UTC](https://www.ruby-forum.com/t/simple-http-authentication-not-working/207899/2 "2011-06-05T23:44:25Z")

</div>

Hello!

On Sun, Jun 05, 2011 at 04:22:46PM -0400, pk899 wrote:

> Below is my config. The folder /site/private is supposed to show the  
> usual HTTP authentication box, but the php files from that folder just  
> start downloading in clear text. What am I doing wrong? The path of the  
> passwd file is correct.

It’s not clear what is the problem you are complaining about.

1. PHP files in clear text? You don’t have any processing for php  
defined in location /site/private. Default behaviour is to serve  
anything as static. So php files being served as static is  
expected result of your config.

2. No HTTP authentication box? It should appear only once per  
browser start (or may not appear at all if you’re brave enough to  
save your password in browser). Check data of the wire or nginx  
logs (access log should be enough) to see if authentication really  
happens.

Maxim D.

---

<div class="post-metadata">

**Author:** ![pk899](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c68b51/32.png) [@pk899](https://www.ruby-forum.com/u/pk899)\
**Post date:** [June 6, 2011, 3:18pm UTC](https://www.ruby-forum.com/t/simple-http-authentication-not-working/207899/3 "2011-06-06T15:18:57Z")

</div>

On 5 Jun 2011 21h22 WEST, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> location  
> ~.\*.(gif|jpg|png|ico|swf|rss|xml|htm|txt|js|css|gz|doc|xls|pdf)$ {  
> expires max; try\_files $uri @backend; log\_not\_found off; }
> 
> location /site/private {  
> auth\_basic “Restricted”;  
> auth\_basic\_user\_file  
> /home/MYDOMAIN/.htpasswds/public\_html/www/private/passwd;  
> }

Right now the /site/private location is for handling static files  
only. You’ve not defined any handler for scripts or any type of  
upstream. So that’s what you should get. Download the file when you  
request it.

— appa
