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