# Basic http auth with proxy pass showing 403/Forbidden

**URL:** <https://www.ruby-forum.com/t/basic-http-auth-with-proxy-pass-showing-403-forbidden/195059>\
**Category:** NGINX\
**Created:** [September 16, 2010, 2:18am UTC](https://www.ruby-forum.com/t/basic-http-auth-with-proxy-pass-showing-403-forbidden/195059 "2010-09-16T02:18:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![strom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@strom](https://www.ruby-forum.com/u/strom)\
**Post date:** [September 16, 2010, 2:18am UTC](https://www.ruby-forum.com/t/basic-http-auth-with-proxy-pass-showing-403-forbidden/195059/1 "2010-09-16T02:18:09Z")

</div>

I am simply trying to password protect a folder and a file in my webapp  
with basic\_auth, but I’m running into some problems.

Here’s the relevant conf info:

```
      location / {
        proxy_pass http://127.0.0.1:80xx;
        proxy_redirect off;

        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For

```

$proxy\_add\_x\_forwarded\_for;

```
        proxy_read_timeout 700;
       }

       location ~ /(admin/.*|test) {
        auth_basic "Restricted";
        auth_basic_user_file conf/htpasswd;
        proxy_pass http://127.0.0.1:9930; # tried both with

```

and without this line  
}

I essentially want to protect my admin directory along with the test  
page, but when I have this location module, I am getting 403 forbidden  
on my webapp for the admin directory and test page.

Thanks.

Posted at Nginx Forum:

> **[Basic http auth with proxy pass showing 403/Forbidden](https://forum.nginx.org/read.php?2,130796,130796#msg-130796)**
>
> I am simply trying to password protect a folder and a file in my webapp with basic\_auth, but I'm running into some problems. Here's the relevant conf info: location / { proxy\_pass http://127.0.0.1:80xx; proxy\_redi

---

<div class="post-metadata">

**Author:** ![strom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@strom](https://www.ruby-forum.com/u/strom)\
**Post date:** [September 16, 2010, 2:25am UTC](https://www.ruby-forum.com/t/basic-http-auth-with-proxy-pass-showing-403-forbidden/195059/2 "2010-09-16T02:25:10Z")

</div>

[quote]I am simply trying to password protect a folder and a file in my  
webapp with basic\_auth, but I’m running into some problems.

Here’s the relevant conf info:

location / {  
proxy\_pass http://127.0.0.1:80xx;  
proxy\_redirect off;

proxy\_set\_header Host $http\_host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;

proxy\_read\_timeout 700;  
}

location ~ /(admin/.\*|test) {  
auth\_basic “Restricted”;  
auth\_basic\_user\_file conf/htpasswd;  
proxy\_pass [http://127.0.0.1:9930](http://127.0.0.1:9930); # tried both with and without this  
line  
}

I essentially want to protect my admin directory along with the test  
page, but when I have this location module, I am getting 403 forbidden  
on my webapp for the admin directory and test page.

Thanks.[/quote]

Sorry, the proxy\_pass in both location modules is supposed to be the  
same port, I was doing some messing around and forgot to change them to  
be the same.

Posted at Nginx Forum:

> **[Re: Basic http auth with proxy pass showing 403/Forbidden](https://forum.nginx.org/read.php?2,130796,130799#msg-130799)**
>
> I am simply trying to password protect a folder and a file in my webapp with basic\_auth, but I'm running into some problems. Here's the relevant conf info: location / { proxy\_pass http://127.0.0.1:80xx; proxy\_redi

---

<div class="post-metadata">

**Author:** ![strom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/2bfe46/32.png) [@strom](https://www.ruby-forum.com/u/strom)\
**Post date:** [September 16, 2010, 6:13am UTC](https://www.ruby-forum.com/t/basic-http-auth-with-proxy-pass-showing-403-forbidden/195059/3 "2010-09-16T06:13:23Z")

</div>

Solution was stupid. I checked the error logs in nginx and found out  
that my relative path was not where I expected it to be.

This works:  
location ~ /(admin/.\*|test) {  
auth\_basic “Restricted”;  
auth\_basic\_user\_file htpasswd;  
}

Posted at Nginx Forum:

> **[Re: Basic http auth with proxy pass showing 403/Forbidden](https://forum.nginx.org/read.php?2,130796,130820#msg-130820)**
>
> I am simply trying to password protect a folder and a file in my webapp with basic\_auth, but I'm running into some problems. Here's the relevant conf info: location / { proxy\_pass http://127.0.0.1:80xx; proxy\_redi
