Frage

I am trying to authenticate several locations together with proxy_pass in Nginx. The Nginx config is following:

server {
    listen       443;
    server_name  example.com;

    location /hg/ {
        rewrite      ^/hg/(.*)$ /$1 break;
        proxy_pass   http://127.0.0.1:8001;

        auth_basic            "hg";
        auth_basic_user_file  hg.htpasswd;

        location /hg/repo1/ {
            auth_basic            "hg-repo1";
            auth_basic_user_file  repo1.htpasswd;
        }

        location /hg/repo2/ {
            auth_basic            "hg-repo2";
            auth_basic_user_file  repo2.htpasswd;
        }
    }
}

The authentication works ok, but the proxy gets broken in nested locations (repo1, repo2). It seems that proxy_pass config is not inherited. So, Nginx returns 404 (on /hg/repo1 and /hg/repo2).

Any hints?

War es hilfreich?

Lösung

You need to repeat proxy_pass for each location block.

Also, there is no function to nesting the location blocks. Usually they are not nested.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top