ある特定のページにユーザ名とパスワードの入力を要求する Basic 認証の設定をします。
[root@localhost ~]# yum -y install httpd-tools |
[root@localhost ~]# vi /etc/nginx/nginx.conf |
# server セクション内に追記 location /auth-basic { auth_basic "Basic Auth"; auth_basic_user_file "/etc/nginx/.htpasswd"; } |
[root@localhost ~]# htpasswd -c /etc/nginx/.htpasswd cent |
New password: # パスワード設定 Re-type new password: Adding password for user cent |
[root@localhost ~]# systemctl restart nginx |
Basic 認証を設定したディレクトリ配下にテストページを作成して動作確認します。 Web アクセスして認証を求められれば、設定 OK です。
認証が成功し、ページが表示されれば OK です。