This will create a auth file for nginx using later.
sudo htpasswd /etc/nginx/.htpasswd user2
#When access http://xxx.com/github/ will proxy the github.com
location /github/ {
index index.html;
auth_basic "Admin";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass https://github.com/;
proxy_set_header X-Real-IP $remote_addr;
}
Below will add configure for nginx use .htpasswd.