# Nginx auth\_basic with proxy pass to tomcat

**URL:** <https://www.ruby-forum.com/t/nginx-auth-basic-with-proxy-pass-to-tomcat/226408>\
**Category:** NGINX\
**Created:** [November 7, 2012, 2:47am UTC](https://www.ruby-forum.com/t/nginx-auth-basic-with-proxy-pass-to-tomcat/226408 "2012-11-07T02:47:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tharanga\_Abeyseela](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/41988e/32.png) [@Tharanga\_Abeyseela](https://www.ruby-forum.com/u/Tharanga_Abeyseela)\
**Post date:** [November 7, 2012, 2:47am UTC](https://www.ruby-forum.com/t/nginx-auth-basic-with-proxy-pass-to-tomcat/226408/1 "2012-11-07T02:47:01Z")

</div>

Hi Guys,

I need to add basic auth to my home page (index.html) (Served by  
nginx) and other directories resides on tomcat7. is there anyway i  
can add only authentication to index.html . i was using the following  
nginx configuration.

server {  
access\_log /var/log/nginx/access.log;  
error\_log /var/log/nginx/error.log;  
index index.html;  
root /var/www/;  
server\_name xxxxxxxx;  
}

```
  location / {
    auth_basic "Restricted";
    auth_basic_user_file /var/www/.htpass;
  }

```

location /next {  
proxy\_pass [http://localhost:8080/next](http://localhost:8080/next);  
proxy\_redirect off;  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;  
proxy\_max\_temp\_file\_size 0;  
}

when i try to add the above config, it asks for the user/pass, but it  
asks for the user/pass when i try to access /next. but i need to add  
authentication only to index.html. problem is using the root  
directory, so all requests will be tunneled through root and prompted  
for a password. but is there any way i can restrict access only to  
index.html, once it authenticated, users will be able to access tomcat  
paths .

Thanks in advance,  
Tharanga

---

<div class="post-metadata">

**Author:** ![Tharanga\_Abeyseela](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/41988e/32.png) [@Tharanga\_Abeyseela](https://www.ruby-forum.com/u/Tharanga_Abeyseela)\
**Post date:** [November 7, 2012, 11:12am UTC](https://www.ruby-forum.com/t/nginx-auth-basic-with-proxy-pass-to-tomcat/226408/2 "2012-11-07T11:12:32Z")

</div>

On 7 Nov2012, at 05:46 , Tharanga Abeyseela  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> index index.html;
> 
> ```
> 
> asks for the user/pass when i try to access /next. but i need to add  
> authentication only to index.html. problem is using the root  
> directory, so all requests will be tunneled through root and prompted  
> for a password. but is there any way i can restrict access only to  
> index.html, once it authenticated, users will be able to access tomcat  
> paths .

You have to add auth\_basic off; to “location /next” or move auth\_basic\*  
directives to  
“location = /index.html”
