NGINX basic auth only for POST

Posted by hokkaido on Server Fault See other posts from Server Fault or by hokkaido
Published on 2010-04-01T17:05:28Z Indexed on 2010/04/01 17:13 UTC
Read the original article Hit count: 225

Filed under:

Hello,

I'm settings up nginx to serve Mercurial repositories. It works when not using basic authentication at all, or when I use basic authentication all over.

What I want to do is to just use basic auth on POST requests, so anyone have pull access, but only authenticated users can push.

I tried the following,

if ($request_method = POST) {
  auth_basic "Restricted";
  auth_basic_user_file /path/to/userfile
}

However it complains about "auth_basic directive is not allowed here".

How can I solve this?

© Server Fault or respective owner

Related posts about nginx