Welcome! Log In Create A New Profile

Advanced

How to "Require User" like Apache in Nginx

March 07, 2014 08:08AM
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
SubjectAuthorPosted

How to "Require User" like Apache in Nginx

flarikMarch 07, 2014 08:08AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 78
Record Number of Users: 5 on November 05, 2014
Record Number of Guests: 210 on November 05, 2014
Powered by nginx    Powered by FreeBSD    PHP Powered    Powered by Percona     ipv6 ready