How to "Require User" like Apache in Nginx

Hi all,

I was just wondering, how to do the following in nginx:

apache.conf:


<Directory /var/www/vhost/aa/htdocs/>
AuthType Basic
AuthUserFile /var/www/auth/htpasswd
AuthName “pass please”
require valid-user
Allow from all

Require user userX

<LocationMatch “/(favicon.ico|style.css|logo.png)”>
Require valid-user

<Location “/location-1”>
Require user userX userY

<Location “/location-2”>
Require user userX userZ


For what I came up with, but I’m still missing the default user ‘userX’
for
everything.

nginx.conf


location / {
auth_basic “Munin”;
auth_basic_user_file /var/www/auth/htpassd;

userX is allow everywhere

below makes site inaccessible

if ( $remote_user != ‘userX’ ) {

return 401;

}

}

location ~ ^/location-1/ {
if ( $remote_user !~ ‘^(userX|userY)$’ ) {
return 401;
}
}

location ~ ^/location-2/ {
if ( $remote_user !~ ‘^(userX|userZ)$’ ) {
return 401;
}
}


Any idea how to solve this?

Regards,

Frodo L.

Posted at Nginx Forum: