nginx - Basic Auth
Updated at 2017-01-03 10:45
Generate passwords for Basic Auth:
sudo htpasswd -c /etc/nginx/sites-enabled/sub.example.com.htpasswd first-user
sudo htpasswd /etc/nginx/sites-enabled/sub.example.com.htpasswd second-user
Check how they look:
cat /etc/nginx/sites-enabled/sub.example.com.htpasswd
first-user:$21d3d12wd12e21e21sceesaw1
second-user:$7qwd897w798qd987wq987qdwq
Use them:
vim /etc/nginx/sites-enabled/sub.example.com.conf
server {
listen 443 ssl http2;
server_name sub.example.com;
ssl_certificate /path/to/key/fullchain;
ssl_certificate_key /path/to/key/privkey;
location / {
include uwsgi_params;
uwsgi_pass unix:/home/sub/run/sub.sock;
auth_basic "sub";
auth_basic_user_file /etc/nginx/sites-enabled/sub.example.com.htpasswd;
}
location /static {
auth_basic off;
root /home/sub/apps/sub/var;
}
}