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
Subject Author Posted

How to "Require User" like Apache in Nginx

flarik March 07, 2014 08:08AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 90
Record Number of Users: 6 on August 08, 2016
Record Number of Guests: 386 on August 02, 2016
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready