もっとhttpd.confの設定
作成 : 2002/08/12
日本語文字コードの指定
ページの文字化けを防ぐために、文字コードを指定する。 ドキュメントの META タグで指定されることが多いが、正式には httpd.conf に記述するらしい。 (富士ゼロックス情報システム株式会社の HTMLにおける文字符号化スキームの明示方法 を見てね)
AddType "text/html; charset=euc-jp" html (日本語 EUC) AddType "text/html; charset=Shift-JIS" html (シフト JIS) AddType "text/html; charset=iso-2022-jp" html (JIS)
ちなみに、CGI(perl)での文字コード指定は、次のようにする。
print("Content-type: text/html; charset=euc-jp\n\n");
AllowOverride
AllowOverride は、.htaccess による設定の上書きを許可するかを指定する。 上位ディレクトリの AllowOverride 設定は、下位ディレクトリに継承される。 詳細は httpdの設定(httpd.conf) を参照。
| All | すべて許可 |
|---|---|
| None | すべて不許可 |
| AuthConfig | 認証関連(AuthUserFile、AuthName、AuthTypeなど) |
| FileInfo | ファイルタイプ(AddTypeなど) |
| Indexes | ディレクトリインデックス |
| Limit | アクセス制限(Order、Allow、Deny) |
| Options | ディレクトリ設定(Options) |
Options
Options は、ディレクトリ制御を指定する。 上位ディレクトリの Options 設定は、下位ディレクトリに継承される。 詳細は httpdの設定(httpd.conf) を参照。
| All | すべて許可 |
|---|---|
| None | すべて不許可 |
| ExecCGI | CGI の許可 |
| FollowSymLinks | シンボリックリンクを許可 |
| SymLinksIfOwnerMatch | オーナーならシンボリックリンクを許可 |
| Includes | SSI を許可 |
| IncludesNOExec | exec を除く SSI を許可 |
| Indexes | ファイル一覧表示を許可 |
上位の設定に追加したい場合は、オプションの前に + をつける(例:+ExecCGI)。 上位の設定から削除したい場合は、オプションの前に - をつける(例:-ExecCGI)。
Order、Allow、Deny
Order、Allow、Deny は、ディレクトリに対するアクセスを制御する。 上位ディレクトリのアクセス制御設定は、下位ディレクトリに継承される。 詳細は httpdの設定(httpd.conf) を参照。
Order deny,allow:特定の相手のみ許可
Order deny,allow Deny from all Allow from xxxx
Order allow,deny:特定の相手のみ拒否
Order allow,deny Allow from all Deny from xxxx
相手を指定するには、次のように記述する。
from all (すべて)
from 192.168. (IPアドレス 192.168.X.X)
from .example.com (ホスト xxx.example.com)
パスワードによるユーザ認証
httpd.conf の <Directory> 〜 </Directory>(または .htaccess)に次のように記述する。
AuthType Basic AuthName "Auth" AuthUserFile .htpasswd Require valid-user
次に、認証用のパスワードファイルを用意する。 パスワードファイル .hpasswd を作成するには、htpasswd コマンドを実行する。 -c オプションをつけると、パスワードファイルが新規作成される。 2回目以降は -c オプションをつけないこと!
# htpasswd -c .htpasswd username
# htpasswd .htpasswd username