Forum: NGINX nginx auth_basic with proxy pass to tomcat

Posted by Tharanga Abeyseela (Guest)
on 2012-11-07 02:47
(Received via mailing list)
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;
        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
Posted by Sergey Budnevitch (Guest)
on 2012-11-07 11:12
(Received via mailing list)
On 7  Nov2012, at 05:46 , Tharanga Abeyseela 
<tharanga.abeyseela@gmail.com> 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"
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.