Apache ツール・ソフトウェア

Apacheの設定

2005年2月6日

Apacheの設定ファイル

ここでは、WindowsにApache2.0.52をデフォルトの設定でインストールした場合を例に説明します。
Apacheのバージョンによって説明の内容が若干異なる可能性もあります。

httpd.confを開く

主な設定は、httpd.confというファイルを編集する事で行います。
デフォルトの設定でC:\Program Files\Apache GroupというフォルダーにApacheをインストールした場合、その下にさらに\Apache2\confというフォルダーがあるので、その中のhttpd.confをエクスプローラ等で探し、テキストエディターで開きます。
他の簡単な方法として、スタートメニューから、「Apache HTTP Server 2.0.52」を探して、その中の「Edit the Apache httpd.conf Configuration File」を選択する事で、httpd.confを開く事ができます。(下図)

httpd.conf の設定を変更する

httpd.conf のデフォルトの設定では

ドキュメント等のHTMLの置き場 CGI等の実行ファイルの置き場
Webブラウザから見た時のパス http://localhost/ http://localhost/cgi-bin/
実際のファイルのパス <導入ディレクトリ>\Apache2\htdocs\ <導入ディレクトリ>\Apache2\cgi-bin\

となっています。これを変更したい場合だけ、httpd.conf の以下の部分を自分の環境に合わせて変更します。
例えば、Webサイト用のファイルを、My Documentの以下の WebPageというフォルダに置いてある場合は、そのフォルダーと自分のHomePageの
/ (ルート)を httpd.conf の設定で対応づけておくと、実際にサーバーにファイルをアップロードする前に自分のPCで動きを確認できるので
便利です。

<省略>
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs"

この設定は http://localhost/ でアクセスした時の/ のフォルダーをどこにするかの設定です。
上記の例では、 "C:/Program Files/Apache Group/Apache2/htdocs" / に対応するように指定しています。
この設定では、C:/Program Files/Apache Group/Apache2/htdocs/ に、index.htmlというファイルを置いた場合、
Webブラウザーから、http://localhost/index.html で開く事ができます。

<省略>
#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ "C:/Program Files/Apache Group/Apache2/cgi-bin/"

この設定は、CGI等のスクリプトを置くディレクトリをどこにするかを設定するためのものです。
上記の例では、C:/Program Files/Apache Group/Apache2/cgi-bin/ というフォルダを、CGIスクリプトを置くための
フォルダーと設定してあり、 そのフォルダーをWebブラウザから見た場合のパスを /cgi-bin/ と指定しています。
C:/Program Files/Apache Group/Apache2/cgi-bin/ フォルダーに、test.cgiというファイルを置いた場合、
そのCGIをWebブラウザーから、http://localhost/cgi-bin/test.cgi でアクセス、実行する事ができます。

#
# "C:/Program Files/Apache Group/Apache2/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "C:/Program Files/Apache Group/Apache2/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

ScriptAlias の設定を変更した場合、
<Directory "C:/Program Files/Apache Group/Apache2/cgi-bin">
・・・・・・・・
</Directory>

C:/Program Files/Apache Group/Apache2/cgi-bin部分のディレクトリのパスも、ScriptAliasでの指定に合わせて変更します。

httpd.confの変更を反映する


Apaceh稼働中にhttpd.confを編集した場合は、設定の変更を反映させるために、Apacheを再起動します。
いろいろ方法がありますが、システムトレイににApacheのアイコンがある場合は、

Apache のアイコン(一番右のアイコンです)で、右クリックして、

「Open Apache Monitor」を選択して、Apacheモニターを開きます。

この様な画面が開くので、「Restart」をクリックします。
また、スタートメニューからも同様な事ができます。

-Apache, ツール・ソフトウェア

Copyright© エンジニアの何でもメモ帳 , 2024 All Rights Reserved.