![]() |
| ◆ | ユーザー認証ページの設定 |
|
ホームページにユーザー認証ページ(パスワードを入力しないと入れないページ)を追加します。 前提条件として“pass”フォルダの中にあるページでユーザー名は“linuxuser”、パスワードは“userpass”とします。 |
|
| ◆ | apache の設定 |
|
apache の設定です。下記のように入力して apache
の設定ファイルを開きます。 下記のように緑色の部分を黄色に変更(書き換え・削除)して下さい。赤文字は説明です。青文字が入力文字です。 |
|
|
[root@linux]# vi /etc/httpd/conf/httpd.conf # # This is the main Apache server configuration file. It contains the # configuration directives that give the server its instructions. # See <URL:http://httpd.apache.org/docs/2.2/> for detailed information. # In particular, see # <URL:http://httpd.apache.org/docs/2.2/mod/directives.html> # for a discussion of each configuration directive. # ↓↓ ↓↓ 途中省略 ↓↓ # <Directory "/home/user/www"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.2/mod/core.html#options # for more information. # Options FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None ↓ AllowOverride All ← All に変更する # # Controls who can get stuff from this server. # Order allow,deny Allow from all </Directory> # ↓↓ ↓↓ 途中省略 ↓↓ # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for requests without a known # server name. # #<VirtualHost *:80> # ServerAdmin webmaster@dummy-host.example.com # DocumentRoot /www/docs/dummy-host.example.com # ServerName dummy-host.example.com # ErrorLog logs/dummy-host.example.com-error_log # CustomLog logs/dummy-host.example.com-access_log common #</VirtualHost> ファイルの最後に下記のような文を追記します <Directory /home/user/www/pass> ← フォルダの指定 SSLRequireSSL ← SSLでのアクセスのみを許可する場合に記述 (尚、先にSSLサーバーを構築しないとエラーになります) AuthName "this directory is SelectUser Only" ← ユーザー認証画面に表示されるメッセージ AuthUserFile /etc/httpd/conf/.passwd ← パスワードファイルの指定 AuthType Basic AuthGroupFile /dev/null Require valid-user </Directory> |
|
| ◆ | ユーザー認証ページ用フォルダの作成 |
|
認証ページ用のフォルダを作成します。 下記のように入力します。ディレクトリ&フォルダ構成は自分の環境に合わせて下さい。 |
|
|
[root@linux]# mkdir /home/xxxx/www/pass/ ← 入力(pass と言うフォルダを作成) |
|
| 次に、ドキュメントルートの所有者変更をします。下記のように入力します。青文字が入力文字です。 | |
|
[root@linux]# chown xxxx. /home/xxxx/www/pass/ ← 入力(ドキュメントルートの所有者を xxxx に変更) |
|
| 続いてディレクトリのアクセス権を変更します。青文字が入力文字です。 | |
|
[root@linux]# chmod 755 /home/xxxx/www/pass/ ← 入力(ドキュメントルート xxxx/www/pass/ のアクセス権を755に変更) |
|
| ◆ | パスワードファイルの作成 |
| パスワード格納ファイルを作成します。 下記のように Apache の設定ファイルのある /etc/httpd/conf へ cd コマンドを使って移動し htpasswd -c .passwd user01 と入力します。 |
|
|
[root@linux]# cd /etc/httpd/conf ← 入力(apache の設定フォルダがある /etc/httpd/conf に移動) [root@linux conf]# htpasswd -c .passwd linuxuser ← 入力(ユーザー linuxuser パスワードファイルの作成) New password: userpass ← 入力(パスワードの入力 userpassは表示されません) Re-type new password: userpass ← 入力(パスワードの入力 userpassは表示されません) Adding password for user linuxuser |
|
| なお、ユーザを追加したい場合は htpasswd .passwd
ユーザ名
と入力して Enter キーを押します。(-c を付けない) 作成したパスワードファイル .passwd を Apache の動作権限で読み取れるように所有者情報を変更します。 下図のように chown apache.apache .passwd と入力して Enter キーを押します。 |
|
|
[root@linux conf]# chown apache.apache .passwd ← 入力(所有者情報を変更) |
|
| ◆ | apache を再読込 |
| 設定を反映させるために apache を再読込させます。 | |
[root@linux]# /etc/rc.d/init.d/httpd reload ← /etc/rc.d/init.d/httpd reloadt を入力(apache の再読込) httpd を再読み込み中: [ OK ] |
|