nginx location match issue auth_basic

Solution 1:

You better do this using a map as the auth_basic directive can contain variables.

map $request_uri $auth {
    default         "off";
    "/app/f?p=3000" "MyRealm";
}


server {

    location / {
        root /etc/nginx/euchet;
    }

    location /app/ {
        auth_basic $auth;
        auth_basic_user_file /etc/nginx/euchet.htpasswd;
        proxy_pass http://172.16.184.2:8080;
        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_set_header REMOTE_ADDR $remote_addr;
    }   

}