Use multiple password files for nginx

I have multiple server blocks in my config, all of them using the same file as auth_basic_user_file. Now we started to work with some external workforce, and we’d like to add some extra users to one of the server blocks, while keeping the original ones, too. Although the documentation doesn’t state it, using multiple auth_basic_user_file is not allowed.

Is there a way to do this, without manually merging the password files together? I’m using nginx 1.11.5


Solution 1:

yes, this is possible. See http://nginx.org/en/docs/http/ngx_http_auth_basic_module.html

  1. Create a separate password file for the server that should have multiple users. Within the server block that should have multiple auth users set auth_basic_user_file path to this new password file.

  2. Insert the original and the additional user info in new password file like this:

    name1:password1
    name2:password2
    
  3. Don't forget to test and reload nginx config:

    nginx -t
    service nginx reload