Limit Authentication to specific username in Nginx
Is it possible to limit authentication in Nginx to a specific username? I.e I have multiple subdomains and want to limit that subdomain to ONLY 1 user. All the users are in 1 .htpassword file. In Apache you can do it as follows:
AuthType Basic
AuthName "Restricted Files"
AuthBasicProvider file
AuthUserFile /usr/local/apache/passwd/passwords
Require user rbowen
However I haven't been able to find a similar way in Nginx.
This is how my current Nginx setup is. I have one of these in each server {} block for each user.
auth_basic "Restricted";
auth_basic_user_file /usr/local/apache/passwd/passwords;
Solution 1:
If I understand the question well, you have a file containing multiple user names and passwords and you want to limit the authentication to a specific user from that file for each server block and keep the configuration centralized ?
Unfortunately you can't do that with nginx, you will need to split the file into multiple ones containing only one user:password pair.