Location regex + if + basic auth to restrict directory access

Francis Daly francis at daoine.org
Sun Mar 10 10:46:57 UTC 2013

On Sun, Mar 10, 2013 at 05:29:18AM -0400, B.R. wrote:

Hi there,

> The *correct* way:
> location ^~ /documents/(\w+) {
>     set $user $1;
>     if ($user != $remote_user) {
>          return 503;
>     }
> }
> Although the syntax is now OK and the configuration is able to be reloaded,
> it doesn't seem to work at all...

I haven't tested the "if" part; but in this case it's mostly likely that
this location{} block is not being used at all.

Your configuration is syntactically correct, so nginx can load it.

But it is not semantically correct, as in "it does not mean what you want
it to mean".


"^~" does not mean "this is a regex location"

Francis Daly        francis at daoine.org

More information about the nginx mailing list