.htpasswd - Nginx password protect root, and separate password for subdirectory -
i'm trying set basic http authentication nginx that's multi-layered. i'd have 1 username & password entire site except subdirectory (url), , separate username & password subdirectory. if navigates subdirectory, want them prompted subdirectory-specific credentials only, , not ones site root.
how set up?
reference: http://nginx.org/en/docs/http/ngx_http_auth_basic_module.html
assume subdirectory url http://www.example.com/admin/.
step 1: create 2 files storing username/password (encrypted) pairs using htpasswd
# secure admin site htpasswd -bc /tmp/admin_passwd.txt admin adminpassword # secure main site htpasswd -bc /tmp/site_passwd.txt user userpassword
step 2: set nginx config:
server { listen 80; server_name www.example.com; root /tmp/www; location ^~ /admin/ { auth_basic "secured site admin"; auth_basic_user_file /tmp/admin_passwd.txt; } location / { auth_basic "secured site"; auth_basic_user_file /tmp/site_passwd.txt; } }
Comments
Post a Comment