Fedora 27
Sponsored Link

Basic認証を利用する2017/12/26

 
Basic認証を利用して、特定のページに対してユーザー認証が必要なようにアクセス制限をかけます。
[1] 例として [/var/www/html/auth-basic] ディレクトリ配下を認証対象として設定します。
[root@www ~]#
vi /etc/httpd/conf.d/auth_basic.conf
# 新規作成

<Directory /var/www/html/auth-basic>
    AuthType Basic
    AuthName "Basic Authentication"
    AuthUserFile /etc/httpd/conf/.htpasswd
    require valid-user
</Directory>
# ユーザーを登録 : -c でファイル新規作成 ( -c は初回のみ付与 )

[root@www ~]#
htpasswd -c /etc/httpd/conf/.htpasswd fedora

New password:    
# パスワード設定

Re-type new password:
Adding password for user fedora
[root@www ~]#
mkdir /var/www/html/auth-basic

[root@www ~]#
vi /var/www/html/auth-basic/index.html
# テストページ作成

<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Test Page for Basic Auth
</div>
</body>
</html>

[root@www ~]#
systemctl restart httpd
[2] クライアントPC で Web ブラウザを起動し、作成したテストページにアクセスします。すると設定通り認証を求められるので、[1] で登録したユーザーで認証します。
[3] アクセスできました。
関連コンテンツ