CuSO4_Deposit's Electrolytic Infodump

nginx password protection

How to password protect a directory with Nginx authentication - nixCraft

To generate passwd file, we need to use apache2-utils (on Debian/Ubuntu).

> sudo apt install apache2-utils
> htpasswd -c /path/to/passwd-file <username>

Then htpasswd will prompt for password. A passwd file can contain several pairs of username-password. When using an existing passwd file, omit -c.

Put the auth-related code into the code block you want to protect, for example, the following protects /app/ directory when accessing foo.domain.tld:

location /app/ {
    server_name    "foo.domain.tld"
    auth_basic          "Restricted Content";
    auth_basic_user_file /path/to/passwd-file;
}

#Nginx