Nginx は直接 basic auth を有効にすることができ、Basic_Auth ログインを有効にすると、クライアントはリクエストヘッダーに Basic_Auth の内容を追加する必要があります。
nginx の設定ファイルの server セクションに以下を追加します。 server {#...... auth_basic "XXXX"; #ログインメッセージ auth_basic_user_file conf/htpasswd; #パスワードファイルのパス #......}
basic auth のパスワードを生成する 2 つの方法 使用 openssl
printf "username:$(openssl passwd -crypt 123456)\n" >>conf/htpasswd
htpasswd を使用
#作成
htpasswd -c -d conf/htpasswd username
#変更
htpasswd -b -d conf/htpasswd username passwd