<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>A Magic Web &#187; .htaccess</title>
	<atom:link href="http://www.a-magic-web.com/server_linux/apatch/htaccess/feed" rel="self" type="application/rss+xml" />
	<link>http://www.a-magic-web.com</link>
	<description></description>
	<lastBuildDate>Sat, 07 Aug 2010 05:57:45 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>会員専用ページに、Apache の Basic 認証を使う</title>
		<link>http://www.a-magic-web.com/server_linux/apatch/htaccess/htaccess_basic_auth.html</link>
		<comments>http://www.a-magic-web.com/server_linux/apatch/htaccess/htaccess_basic_auth.html#comments</comments>
		<pubDate>Wed, 13 Jan 2010 12:17:59 +0000</pubDate>
		<dc:creator>vohedge</dc:creator>
				<category><![CDATA[.htaccess]]></category>

		<guid isPermaLink="false">http://www.a-magic-web.com/server_linux/apatch/htaccess/htaccess_basic_auth.html</guid>
		<description><![CDATA[ほとんどのレンタルサーバーでは Basic 認証を GUI で設定できるツールを用意されていると思いますが、そういった ツールがない環境で設定する機会があったので、メモしておきます。作業はssh で接続して行いました。 設定方法 .htaccess ファイルの作成 [centos@localhost temp]$ vi .htaccess AuthType Basic AuthName "Restricted Files" AuthUserFile /var/www/html/temp/.htpasswd Require user test .htpasswd ファイル（パスワードファイル）の作成 [centos@localhost temp]$ htpasswd -c /var/www/html/temp/.htpasswd test New password: Re-type new password: Adding password for user test 以上の手順だけで、ドキュメントルート以下の temp ディレクトリに Basic 認証をかけることができました。 Basic 認証を昨日させているモジュール Apache 2.1 より前のバージョンでは、mod_auth によって Basic 認証機能が実装されている模様。そのため、Basic [...]]]></description>
			<content:encoded><![CDATA[<p>ほとんどのレンタルサーバーでは Basic 認証を GUI で設定できるツールを用意されていると思いますが、そういった<br />
ツールがない環境で設定する機会があったので、メモしておきます。作業はssh で接続して行いました。</p>
<h3>設定方法</h3>
<p>.htaccess ファイルの作成</p>
<div class="command">
<pre>[centos@localhost temp]$ vi .htaccess
AuthType Basic
AuthName "Restricted Files"
AuthUserFile /var/www/html/temp/.htpasswd
Require user test</pre>
</div>
<p>.htpasswd ファイル（パスワードファイル）の作成</p>
<div class="command">
<pre>[centos@localhost temp]$ htpasswd -c /var/www/html/temp/.htpasswd test
New password:
Re-type new password:
Adding password for user test</pre>
</div>
<p>以上の手順だけで、ドキュメントルート以下の temp ディレクトリに Basic 認証をかけることができました。</p>
<h3>Basic 認証を昨日させているモジュール</h3>
<p>Apache 2.1 より前のバージョンでは、mod_auth によって Basic 認証機能が実装されている模様。そのため、Basic 認証を使うには、httpd.conf で mod_auth.so が読み込まれていることが必要。</p>
<div class="command">
<pre>LoadModule auth_module modules/mod_auth.so</pre>
</div>
<p>Apahe 2.1 以降では、mod_auth_basic モジュールで実装されているようです。今回は Apache 2.0 を使っているので、こちらは確認していません。モジュールのインストールから始める必要のある環境は、通常の WEB サーバーであれば、ほとんどないのではないかと。</p>
<h3>その他必要な設定</h3>
<p>Basic 認証の設定を書き込む場所は、Apache の設定ファイルである httpd.conf に直接書くか、該当のディレクトリに .htaccess ファイルを設置する方法の 2通り。.htaccess を使う場合は、httpd.conf に以下の設定が必要です。</p>
<div class="command">
<pre>AllowOverride AuthConfig</pre>
</div>
<p>もちろん、AllowOverride All でも。 普段は、httpd.conf を触ることはしないので、.htaccess を設置しました。 httpd.conf で設定を行う場合でも、設定項目は同じです。</p>
<h3>使用したディレクティブ</h3>
<blockquote><p>AuthType : ユーザ認証の種類を指定。BasicかDigestを指定。<br />
AuthName : ここで AuthName に指定した文字列が、大部分のブラウザのパスワードダイアログに表示される。<br />
AuthUserFile : 認証に使用するユーザとパスワードの一覧が格納されている、テキストファイルの名前を設定。<br />
Require : 認証に使用するユーザー名を指定。</p></blockquote>
<h3>htpasswd コマンド</h3>
<p>パスワードファイルの作成に必要なコマンド。Apache に付属します。以下の構文で実行します。</p>
<div class="command">
<pre>htpasswd -c Filename username</pre>
</div>
<p>書式が分かれば手入力でも作成はできるが、通常はこのコマンドを使う。主なオプションは、 以下の通り。</p>
<blockquote><p>-c : 新しいパスワードファイルを作成。同名のパスワードファイルがすでに存在する場合は、既存の内容が上書きされる。<br />
-n : テスト実行用のオプション。他のオプションなどの構文エラーがないかなどの確認に用いる。-c と一緒に使うことはできない。<br />
-m : パスワードをファイルに書き込む際、MD5 でハッシュした値を書き込みます。<br />
-d : パスワードをファイルに書き込む際、CRYPT でハッシュします（デフォルト）。<br />
-p : パスワードをファイルに書き込む際、ハッシュせずに、プレーンなテキストで書き込みます。<br />
-s : パスワードをファイルに書き込む際、SHA でハッシュします。<br />
-D : ユーザーを削除します。</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.a-magic-web.com/server_linux/apatch/htaccess/htaccess_basic_auth.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
