How to "Require User" like Apache in Nginx
flarik
nginx-forum at nginx.us
Fri Mar 7 13:08:04 UTC 2014
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
</Directory>
<Location />
Require user userX
</Location>
<LocationMatch "/(favicon.ico|style.css|logo.png)">
Require valid-user
</LocationMatch>
<Location "/location-1">
Require user userX userY
</Location>
<Location "/location-2">
Require user userX userZ
</Location>
# -----------------------------------------------------------------------
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 Larik
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,248229,248229#msg-248229
More information about the nginx
mailing list