このページでは、Webminを使用してApacheWebサーバーを構成する方法について説明します。 。仮想ホスト、IPアクセス制御、パスワード制限などをカバーしています。
Apacheの紹介
Apacheは、そのゼロコスト、幅広い可用性、および大規模な機能セットにより、インターネットで最も人気のあるHTTPサーバーです。すべてのLinuxディストリビューションには標準パッケージとして含まれており、Webminでサポートされている他のすべてのUnixバリアントにインストールまたはコンパイルできます。ただし、テキスト構成ファイルには非常に多くのオプションディレクティブが定義されているため、経験の浅い管理者が設定するのは難しい場合があります。
最初に導入されてから何年にもわたって、Apacheの多くのバージョンがリリースされてきました。 1.0から始まり、現在の1.3および2.2シリーズに移行すると、各バージョンにはより多くの機能とオプションが含まれています。内部実装が大幅に変更されたとしても、基本的なWebサービス機能と構成ファイルのレイアウトは基本的に同じままです。
Apacheはモジュラー設計であり、各モジュールがその全体的な機能セットの一部を担当します。 Apacheのほぼすべてのインストールに含まれているいくつかの標準モジュールがあり、さらに多くはオプションであるか、個別にダウンロードする必要があります。モジュールは、Webサーバーの実行可能ファイルにコンパイルすることも、実行時に共有ライブラリから動的にロードすることもできます。このモジュラーアーキテクチャを使用すると、特定のシステムに有用な機能を提供しないモジュールをロードする必要がなくなるため、メモリを節約できます。
Apacheは、複数のテキストファイルから構成を取得します。各テキストファイルには、通常は1行に1つずつ、一連のディレクティブが含まれています。各ディレクティブには名前と1つ以上の値があり、ログファイルへのパスや一部のファイルのMIMEタイプなどのオプションを設定します。 Apacheが認識するディレクティブは、使用中のモジュールによって異なります。ほとんどのモジュールは、提供する機能を構成するためのいくつかのディレクティブのサポートを追加します。
多くの場合、1つのサーバーで複数のWebサイトをホストする必要があります。 Apacheは、ブラウザーによって要求されたWebサイトに応じて異なる構成を使用するように構成できます。これらの各サイトは仮想ホストと呼ばれ、構成ファイルで特別な
同様に、
単一のディレクトリにのみ適用されるディレクティブを作成する別の方法は、 .htaccessという名前の特別な構成ファイルにそれらを配置することです。 これはディレクトリ自体にあります。多くの場合、これらのファイルは通常のユーザーによって作成されるため、マスター構成ファイルへのフルアクセスを必要とせずに独自のWebサイトを構成できます。これは、サーバーの所有者によって設定されたWebサイトが1つしかないシステムではなく、それぞれが異なるUnixユーザーによって所有されている複数のサイトをホストするシステムで非常に役立ちます。
ApacheWebサーバーモジュール
これは、Apacheのほぼすべての機能を構成できるため、最も複雑で強力なWebminモジュールの1つです。システムにインストールされているApacheのバージョンとそれが使用するモジュールを判別し、それに応じてユーザーインターフェイスを調整して、Webサーバーが理解できるディレクティブのみを編集できるようにします。ただし、インターフェイスは通常、Apacheのすべてのバージョンで同じです。
非常に多くのディレクティブがあり、モジュールはそれらすべての構成を許可しようとするため、ディレクティブをプロセスと制限、ネットワークとアドレス、CGIプログラムなどのカテゴリにグループ化します。これらのカテゴリは、モジュールで仮想サーバー、ディレクトリ、またはオプションファイルを開いたときに表示されるアイコンで表されます。いずれの場合も、アイコンをクリックすると、各カテゴリの設定を表示および編集できます。
Apacheには、多数の標準モジュールと、他の人によって開発されたさらに多数の個別のモジュールがあります。 Webminは、mod_perlやmod_phpなど、これらの非標準のほとんどでディレクティブの編集をサポートしていません。ただし、理解できない構成ファイルディレクティブは安全に無視されるため、手動で行ったサポートされていないモジュールの設定が損なわれることはありません。
Apacheモジュールを開くと、以下に示すタブ付きページが表示されます。

最初のタブには、グローバルオプションのさまざまなカテゴリのアイコンと、いくつかの追加機能があります。 2番目は現在のすべての仮想サーバーのリストで、3番目は新しい仮想ホストを追加するためのフォームです。システムに非常に多数の仮想サーバー(デフォルトでは100を超える)がある場合は、代わりにサーバーを検索するための検索フォームが表示されます。最初のサーバーは常に特別なデフォルトサーバーになります 、他のすべての仮想サーバーに適用され、他のサーバーには適用されない要求を処理するディレクティブが含まれています。
当然、システムにApacheがインストールされていない場合、Apacheモジュールは機能しません。この場合、メインページには、モジュール構成フォームまたは仮想サーバーのリストの代わりにエラーメッセージが表示されます。すべてのLinuxディストリビューションには、CD-ROMまたはWebサイトにパッケージが含まれているため、続行する前に、ソフトウェアパッケージモジュールを使用してそこからインストールしてください。
モジュールは、Apacheの実行可能ファイルと構成ファイルがディストリビューションのパッケージで使用される場所にあることを前提としているため、手動でコンパイルしてインストールした場合、ソフトウェアがインストールされていないことについて同じエラーが報告されます。この場合は、 Module Configをクリックしてください。 システムの正しい場所にパスをリンクして調整します。
デフォルトでApacheを含まないバージョンのUnixでは、Webminは、www.apache.orgの標準ソースディストリビューションからインストールされると想定しています。 OSで利用できるようになっているオプションのパッケージからWebサーバーをインストールした場合、メインページにインストールされていないというメッセージが表示されるため、モジュール構成を調整する必要があります。
モジュールのユーザーインターフェイスは非常に複雑で、Apache構成ファイルの複雑さと能力のために、多数のページ、フォーム、およびサブページがあります。ただし、次のように、モジュール全体の多くのページで繰り返されるインターフェースの要素があります。
- カテゴリアイコン 仮想サーバー、ディレクトリ、またはオプションファイルのアイコンをクリックすると、ページの上部にMIMEタイプやCGIプログラムなどの名前のアイコンの表が表示されます。これらの各アイコンの下には、下にあるアイコンのラベルに関連するオプションを構成するためのフィールドとテーブルがあります。この一般的に使用されるレイアウトでは、1ページに表示するにはフィールドが多すぎるため、編集可能な多数のApacheオプションがカテゴリに分類されます。表示される正確なアイコンとその下のフィールドは、編集しているWebサーバー構成の部分、およびインストールされているApacheのバージョンによって異なります。ただし、基本的なレイアウトは常に同じです。
- テーブルフィールド 多くのフォームでは、一部のフィールドは、MIMEタイプやそれに関連するファイル拡張子など、複数の値を入力するためにテーブルを使用します。各テーブルに含めることができる行数に制限はありませんが、Webminは一度に各テーブルに1つの空の行のみを表示します。これにより、テーブルがたくさんあるフォームのサイズを抑えることができますが、テーブルに追加できる新しい行は一度に1つだけです。複数追加するには、フォームを保存してから再入力する必要があります。これにより、入力した行の下に新しい空白行が表示されます。
以下のセクションでは、CGIスクリプトの有効化やMIMEタイプの設定などを行うときに、クリックするアイコンと入力するテーブルをより詳細に説明します。
Apacheの起動と停止
ブラウザがシステム上のApacheWebサーバーに接続する前に、そのサーバープロセスを開始する必要があります。モジュール内のいずれかのページの上部を確認することで、現在実行されているかどうかを確認できます。 変更の適用というラベルの付いたリンクの場合 およびApacheを停止 が表示されたら、現在アクティブです。ただし、リンク* Start Apache *のみが表示される場合は、まだ実行されていません。
開始するには、Apacheの開始をクリックします リンク。すべてがうまくいけば、現在表示しているページが再表示され、上部のリンクが変更されて、現在実行中であることが示されます。それ以外の場合は、何がうまくいかなかったかを説明するエラーメッセージが表示されます。ほとんどの場合、原因は構成ファイルのエラーです。
実行中にWebサーバーを停止するには、[Apacheの停止]をクリックします。 モジュールのページのいずれかにリンクします。万が一、Webminがサーバーを停止できない場合は、エラーメッセージページが表示されます。正常に停止すると、同じページが再表示され、上部のリンクが変更されて、実行されていないことが示されます。
Apacheがアクティブな場合、すべてのページに変更の適用があります 現在の構成を再ロードするようにWebサーバーに通知するために使用できる上部のリンク。このモジュールに変更を加えた後(.htaccessファイルの変更を除く)、このリンクをクリックしてアクティブにする必要があります。メインページに[適用]ボタンがある他のWebminモジュールとは異なり、このモジュールにはすべてのページにボタンがあるため、変更を加えるたびにインデックスに戻る必要はありません。
ウェブサーバーのページを編集する
このセクションでは、クライアントがApacheWebサーバーに接続したときに表示されるシステム上のファイルを検索して編集する方法について説明します。これを行う方法をすでに知っている場合は、スキップして次のセクションに進んでください。
Apacheが最初にパッケージまたはソースからインストールされるとき、その初期構成では通常、仮想サーバーはセットアップされません。代わりに、デフォルトのサーバーのみが存在し、ポート80で接続するすべてのクライアントにページを提供します。Webブラウザを実行してURL http://_ yourhostname_ /、またはhttp:// _ localhost_ /にアクセスすると、デフォルトのページを表示できます。 Webminと同じシステムでブラウザを実行しています。表示されるページは、おそらくApacheまたはLinuxディストリビューションで提供されているものだけです。
Apacheがファイルを提供するドキュメントルートディレクトリは、モジュールのメインページのデフォルトサーバーの横に表示されます。 アイコン。たとえば、Redhat Linuxでは、このディレクトリはデフォルトで/ home / httpd/htmlです。このディレクトリ内のファイルは、rootとしてログインするか、Webminのファイルマネージャーモジュールを使用して編集できます。行った変更は、すぐにWebサイトに反映されます。
システムが単一の静的Webサイトをホストするだけの場合は、Apacheの他の側面を構成する必要がない場合があります。 HTML、画像、その他のファイルをディレクトリとそのサブディレクトリにアップロードまたはコピーするだけで、必要なサイトを作成できます。最も重要なファイルはindex.htmlで、ブラウザが特定のページを要求しない場合は常にApacheによって提供されます。ほとんどの人は最初にhttp:// _ yourserver_ /にアクセスするため、index.htmlページが最初に表示されます。
編集を容易にするために、ドキュメントのルートディレクトリとそのすべてのファイルの所有権をroot以外のユーザーに変更することをお勧めします。ただし、Apacheサーバープロセスが実行されるユーザー(通常はhttpdという名前)が引き続き読み取り可能であることを確認する必要があります。これを行う最も簡単な方法は、すべてのファイルとディレクトリを誰でも読み取り可能で実行可能にすることです。
新しい仮想ホストの作成
システムで複数のWebサイトをホストする場合は、それぞれにApache仮想ホストを作成する必要があります。サイトを追加する前に、そのアドレスを、システム上のDNSサーバーまたは別のホストのいずれかでDNSに登録する必要があります。サイトのファイルを、ドキュメントのルートディレクトリを所有しているユーザーとは別のUnixユーザーが所有する場合は、そのユーザーも最初に作成する必要があります。
上記の手順を含む、仮想サーバーを追加するためのプロセス全体は次のとおりです。
- www.example.com など、新しいWebサイトのURLで使用するホスト名を決定します 。
- 新しいサイトをIPベースにするか、名前ベースにするかを決定します。名前ベースのサイトは、古いブラウザを除くすべてのブラウザで正常に機能するため、最近では断然最良の選択です。 IPベースのサイトはどのブラウザでも機能しますが、システムに追加するには独自のIPアドレスが必要です。 IPアドレスが不足していることが多いため、これは、ドメインにも仮想FTPまたはPOP3サーバーをセットアップする必要がある場合にのみ意味があります。
- サイトをIPベースにする場合は、ネットワーク構成モジュール(ネットワーク構成で説明)を使用して、システムの外部ネットワークインターフェイスに新しい仮想IPアドレスを追加します。起動時にアクティブになり、現在アクティブになっていることを確認してください。システムにISPによって割り当てられた静的インターネットIPアドレスが1つしかない場合、システムに追加した追加の仮想IPアドレスは機能しません。その場合、代わりに名前ベースの仮想サーバーを使用するか、ISPに複数のアドレスを割り当てるように要求する必要があります。
- example.comの場合 ドメインはすでにDNSサーバーに存在します。www.example.comのレコードを追加してください システムの外部IPアドレス(名前ベースのサイトの場合)または前の手順で選択したアドレス(IPベースのサイトの場合)を使用します。ドメインがまだ存在しない場合は、ドメインをDNSサーバーに追加し、NetworkSolutionsなどのDNSレジストラに登録する必要があります。いずれにせよ、BIND DNSサーバーページでは、レコードとドメインを追加する方法について詳しく説明しています。
- サイトが標準のHTTPポート80(ほとんどの場合必要なもの)を使用する場合は、手順8にスキップできます。それ以外の場合は、ApacheWebサーバーモジュールのメインページでネットワークとアドレス 下の最初のスクリーンショットに示されているフォームを表示するためのアイコン。
- アドレスとポートを聞くの空の行 テーブルで、すべてを選択します 住所の下 列を選択し、デフォルトの選択を解除します ポートの下 桁。次に、WebサイトのTCPポート番号をその横のフィールドに入力し、[保存]をクリックします。 ページ下部のボタン。
- モジュールのメインページで、既存の仮想ホストのリストの下にある[*新しい仮想サーバーの作成*]フォームまで下にスクロールします。
- IPベースの仮想サーバーをセットアップする場合は、アドレスで フィールドには、手順3で追加した仮想IPアドレスを入力する必要があります。名前ベースの仮想サーバーを設定する場合は、代わりにシステムの外部IPアドレスをフィールドに入力します。 Apacheサーバーが任意のIPアドレスで名前ベースの接続を受け入れるように構成されている場合は、任意を選択できます。 代わりに、このフィールドのオプション。詳細については、以下の説明を参照してください。新しい仮想サーバーが80以外のポートを使用し、そのポート上の唯一のサーバーになる場合は、任意を選択できます。 ポートに着信するすべてのリクエストを処理するためのオプションもあります。
- IPベースの仮想サーバーをセットアップする場合は、名前の仮想サーバーアドレスの追加の選択を解除します。 チェックボックス。名前ベースのサーバーの場合は、有効のままにしておく必要があります。
- 新しい仮想ホストが非標準のポートを使用する場合は、ポートの最後のオプションを選択します フィールドに入力し、その横のフィールドに番号を入力します。
- ドキュメントルート フィールドに、このWebサイトのファイルを含むディレクトリへのフルパスを入力します。たとえば、これは / home / example / wwwのようになります。 。
- サーバー名 フィールドに、クライアントが www.example.comなどのこのWebサイトを参照するために使用するホスト名を入力します 。 web.example.comなどの複数の名前を入力できます およびexample.com これが名前ベースのサーバーであり、いくつかの異なるURLでアクセスできる必要がある場合。
- システム上にすべての仮想ホストを含む別のファイルがない限り、ファイルに仮想サーバーを追加したままにします。 フィールドを標準のhttpd.confファイルに設定 。それ以外の場合は、選択したファイルを選択できます その横のフィールドにパスを入力します。選択したファイルが実際にApacheによって使用されていることを確認してください(httpd.confのIncludeディレクティブなど)。そうでない場合、仮想サーバーは役に立たず、Webminに表示されません。仮想ホストの保存に常に同じ別のファイルを使用する場合は、仮想サーバーを追加するファイル ApacheWebサーバーモジュールの設定で説明されているフィールド 以下のセクションが役立つ場合があります。設定されている場合は、このモジュール構成オプションで設定されたファイルに追加するために、[*仮想サーバーをファイルに追加*]フィールドに追加するオプションがあります。
- Webminにすべてのディレクティブを別の仮想サーバーから作成中の仮想サーバーにコピーさせるには、ディレクティブのコピー元から選択します。 メニュー。これは、すべての仮想ホストの構成が類似している場合に役立ちます。
- フォームへの入力が完了したら、[作成]をクリックします ボタン。新しい仮想サーバーは、Apache構成ファイルとメインページのサーバーのリストに追加されます。
- 新しい仮想サーバーのアイコンをクリックすると、下の2番目のスクリーンショットに示されているオプションページが表示されます。
- ディレクトリごとのオプションの下のフォームまで下にスクロールします 、手順11で選択したドキュメントルートディレクトリをパスに入力します。 分野。 タイプを確認してください ディレクトリに設定されています 、および正規表現? 完全一致へのフィールド 。
- 作成をクリックします ボタンをクリックして、ディレクトリの構成ファイルに新しいセクションを追加します。これは、デフォルトのApacheディレクトリ構成で拒否されているファイルを参照する権限をクライアントに付与できるようにするために必要です。
- 仮想サーバーオプションページに追加されたディレクトリの新しいアイコンをクリックします。これにより、下の3番目のスクリーンショットに示されているディレクトリオプションページに移動します。
- ドキュメントオプションをクリックします アイコンをクリックし、表示されるフォームでディレクトリオプションを変更します フィールドを*以下で選択*します。 ディレクトリの設定の下 列で、ディレクトリインデックスの生成のエントリを変更します はい 。次に、保存をクリックします ページ下部のボタン。
- すべての変更をアクティブにするには、[変更を適用]をクリックします ページ上部のボタン。
- これで、あなたまたは仮想サーバーを所有するユーザーは、ドキュメントのルートディレクトリへのファイルの追加を開始できます。 WebブラウザでURL(http://_www.example.com_/など)を開いてテストし、すべてが正しく機能していることを確認できます。


ApacheがHTTPリクエストを受信すると、最初にリクエストの対象となる仮想サーバーを特定する必要があります。最初に、ホスト名がクライアントによって要求されたホストと一致し、アドレスとポートがクライアントが接続したものと同じである名前ベースの仮想サーバーを探します。何も見つからない場合は、アドレスとポートに最初に定義された仮想サーバーが代わりに使用されます。見つからない場合は、要求はデフォルトサーバーによって処理されます。
名前ベースの仮想サーバーは、名前仮想サーバーのアドレスにリストされているアドレスでのみ使用できます。 グローバルネットワークとアドレスページのフィールド。上記の手順に従うと、新しい仮想サーバーを作成するときに、アドレスがこのリストに自動的に追加されます。システム上のすべての仮想サーバーが名前ベースになる場合は、このページを開き、フィールドに*と入力して、[保存]をクリックします。 Apacheが任意のIPアドレスでそのような要求を処理するようにします。これは、システムに動的に割り当てられたIPアドレスがあり、複数の仮想ホストにサービスを提供する場合にも意味があります。
仮想サーバーを作成したら、次の手順に従って設定を編集または削除できます。
- モジュールのメインページで、仮想サーバーのアイコンをクリックします。これにより、上のスクリーンショットに示されているサーバーオプションページに移動します。
- 仮想サーバーの詳細まで下にスクロールします ページの下部にあるフォーム。
- 住所を変更する 、ポート およびその他のフィールドを任意の場所に移動して、[保存]をクリックします ボタン。これらのフィールドは、仮想サーバー作成フォームの場合と同じ意味を持ちます。ただし、名前ベースの仮想サーバーでアドレスを変更する場合は、グローバルな[ネットワークとアドレス]ページでもアドレスを変更する必要がある場合があります。または、仮想サーバーとそれに含まれるすべての構成ディレクティブを削除する場合は、[仮想サーバーの削除]をクリックします。 代わりにボタン。
- モジュールのメインページに戻り、変更の適用をクリックします。 リンクをクリックして、新しい設定をアクティブにします。
デフォルトサーバーの設定を変更したり、削除したりすることはできません。
ディレクトリごとのオプションの設定
Apacheでは、すべての仮想サーバーまたは1つの仮想サーバーのいずれかに対して、特定のディレクトリにさまざまなオプションを指定できます。ディレクトリを含めて、Apacheサーバー上の3種類のオブジェクトに適用されるオプションを実際に設定できます。
- ディレクトリ オプションは、指定されたディレクトリと、そのディレクトリまたはそのディレクトリに含まれるサブディレクトリ内のすべてのファイルに適用されます。
- ファイル オプションは、任意のディレクトリ内の指定された名前のファイルに適用されます。
- 場所 オプションは、パスが指定された場所で始まるURLによって要求されたすべてのファイルまたはディレクトリに適用されます。たとえば、URL http://www.example.com/foo パスは/fooになります 。
Apacheはリクエストを処理するたびに、適用されるオプションを決まった順序でチェックします。ディレクトリセクションと.htaccessファイルからのものが最初に読み取られるため、最も具体的なディレクトリが最初にチェックされます。次に、ファイル、場所のセクションが続きます。次に、要求が行われた仮想サーバーからのオプション(存在する場合)が読み取られ、最後にデフォルトサーバーからのオプションが読み取られます。

これは、ディレクトリに設定されたオプションが、上位レベルのディレクトリまたはそのディレクトリがメンバーになっている仮想サーバーに設定された同じオプションを上書きすることを意味します。ディレクトリ、ファイル、またはURLの場所のオプションを設定するには、次の手順に従います。
- 設定するオプションはディレクトリに適用されますが、仮想サーバーまたはデフォルトサーバーのいずれかで定義する必要があります。それらが仮想ホストの下にある場合、それらは選択されたディレクトリまたはURLの場所にあるファイルに対するそのサーバーへの要求にのみ適用されます。ただし、それらがデフォルトサーバーの下にある場合は、ディレクトリ内のファイルに対する仮想ホストへの要求が有効になります。モジュールのメインページで、デフォルトサーバーのいずれかをクリックします アイコンまたはディレクトリオプションを制限する仮想サーバーのアイコン。ディレクトリの場合、各仮想ホストには通常、独自の個別のドキュメントルートディレクトリがあるため、通常、オプションをデフォルトサーバーの下に配置するのが最も簡単です。ただし、URLの場所のオプションは、それらが関連する仮想サーバーの下に配置する必要があります。これは、同じURLパスが複数の仮想ホストで異なる方法で使用される可能性があるためです。同じことがファイルオプションにも当てはまります。
- 表示されるサーバーオプションページ(図29-4を参照)で、[ディレクトリごと、ファイル、または場所のオプションの作成]フォームまで下にスクロールします。
- タイプから メニューで、上記のオプションの1つを選択します。
- ディレクトリのオプションを設定する場合は、そのディレクトリをパスに入力します / home / example / www / imagesなどのフィールド 。 / home / example / w *などのワイルドカードパスを入力することもできます 、これにより、一致するすべてのディレクトリにオプションが適用されます。 URLの場所にオプションが設定されている場合は、ホスト名の後のURLの部分を[パス]フィールドに入力します( / images など)。 。 *や?などのシェルワイルドカード文字を使用することもできます。 URLにも。ファイルのオプションを設定する場合は、パスにファイル名を入力します secret.htmlなどのフィールド 。繰り返しになりますが、ファイル名にはワイルドカード文字を使用できます(例: secret*。)。
- ディレクトリ、ファイル名、またはURLの場所で複雑な正規表現を使用できるようにする場合は、 Regexp?を設定します。 正規表現に一致するフィールド 。これにより、[、]、+、などのPerl正規表現文字を使用できるようになります。および*パス内。
- 作成をクリックします ボタンをクリックして、新しいディレクトリセクションをApache構成に追加します。仮想サーバーのオプションページが再び表示されますが、ディレクトリの新しいアイコンが表示されます。
ディレクトリ、URLの場所、またはファイル名の新しいアイコンを作成したので、それに適用するオプションを設定できます。ディレクトリごとの最も一般的な変更の1つは、ブラウザがhttp://www.example.com/images/のようなURLでディレクトリを要求したときにファイルを一覧表示する方法を設定することです。デフォルトでは、ディレクトリにindex.htmlファイルがある場合はそれが表示され、そうでない場合は、そこに含まれるすべてのファイルを一覧表示するページが代わりに表示されます。
インデックスファイルの名前、ディレクトリリストのスタイル、またはインデックス作成に関連するその他の設定を変更する場合は、次の手順に従います。
- 仮想サーバーのオプションページで、構成するディレクトリのアイコンをクリックします。これにより、図29-5に示すディレクトリオプションページが表示されます。
- ディレクトリインデックスをクリックします アイコンをクリックして、インデックス作成とリストのオプションを設定するためのフォームを表示します。
- ディレクトリリストの外観を変更するには、[*ディレクトリインデックスオプション*]フィールドを以下で選択に設定します。 その下のボックスのフィールドを変更します。デフォルトでは、非常にわかりやすいファイルのリストが生成されますが、次のオプションを設定することで、リストを拡張できます。
- 派手なディレクトリインデックスを表示する 有効にすると、ファイルのリストにアイコン、サイズ、変更日が含まれます。
- 説明としてHTMLタイトルを表示する 有効にすると、HTMLファイルの説明は
タグから取得されます。 - アイコンの高さ このオプションを使用すると、ディレクトリリストに含まれるアイコンの高さを変更できます。 デフォルトに設定されている場合 、標準のApacheオプションの高さが使用されます。
- アイコンの幅 前のオプションと同様に、これにより、ディレクトリリスト内のアイコンの幅を指定できます。
- ユーザーによる列の並べ替えを許可する これを有効にすると、ユーザーは、ファイルが表示されていると想定して、列見出しをクリックすることでファイルのリストを並べ替えることができます。
- ファイルの説明を表示する 有効にすると、ディレクトリリストには、MIMEタイプまたはHTMLタイトルから取得した各ファイルの説明が含まれます。
- HTMLヘッダータグを出力する 有効にすると、ディレクトリリストには、すべてのHTMLページを開始する通常のタグとタグが含まれます。独自のヘッダーファイルとフッターファイルを提供する場合にのみ、オフにする必要があります。
- 最終変更時刻を表示 有効にすると、ディレクトリリストに各ファイルの最終変更日が含まれます。
- ファイルサイズを表示 有効にすると、リストには各ファイルのサイズが含まれます。
- リンクにアイコンを含める このオプションを有効にすると、リスト内のアイコンがファイル自体へのリンクになります。それ以外の場合は、ファイル名のみがリンクになります。
- ファイル名の幅 このオプションは、ディレクトリリストのファイル名列の長さを制御します。文字数を入力するか、*を入力して、列のサイズを最長のファイル名の長さにすることができます。
- 説明の幅 このオプションは、ディレクトリリストの説明列の長さを制御します(存在する場合)。文字数を入力するか、*を入力して、最も長い説明の長さに列のサイズを設定できます。
- 最初にディレクトリを表示する 有効にすると、他のファイルに関係なく、リストにはファイルの上にあるディレクトリが表示されます。使用可能なオプションは、システムにインストールしたApacheのバージョンによって異なります。上記のリストはバージョン1.3.19で有効ですが、新しいリリースを使用している場合は、さらに多くのオプションを利用できる場合があります。
- ブラウザがディレクトリを要求したときにApacheがデフォルト以外のファイル(通常はindex.html)を返すようにする場合は、ファイル名のリストをディレクトリインデックスファイルに入力します。 分野。 1つ以上入力でき、最初に見つかったものが使用されます。インデックスファイルが見つからない場合は、手順3で選択したオプションを使用したディレクトリリストが代わりにブラウザに返されます。
- ディレクトリ内のファイルのリストを生成するときにWebサーバーが特定のファイルを無視するようにするには、それらのファイル名をディレクトリインデックスで無視するファイルに入力します。 分野。 *。docなどの正規表現では、シェルワイルドカードを使用できます。 。
- ディレクトリリストの先頭にHTMLファイルを挿入するには、そのファイル名(ディレクトリに対して)をディレクトリインデックスヘッダーファイルに入力します。 分野。
- 同様に、ディレクトリリストの最後にファイルを追加するには、そのファイルをディレクトリインデックスフッターファイルに入力します。 分野。
- ディレクトリのデフォルトの順序を制御するには、デフォルトの選択を解除します ディレクトリインデックスの並べ替え フィールドをクリックし、その横にある2つのメニューから並べ替える順序と列を選択します。
- *ディレクトリインデックスの説明*テーブルに入力することで、ファイルの説明を設定できます。テーブルの空の行で、説明にファイルを説明する短いメッセージを入力します 列、およびファイル名内のファイル名またはワイルドカード名のリスト 桁。一度に表示される空の行は1つだけなので、複数の説明を入力する場合は、各説明を追加した後でこのページに再度アクセスする必要があります。
- 最後に、[保存]をクリックします ページの下部にあるボタンをクリックして変更を保存し、ディレクトリオプションページに戻ります。それらをアクティブにするには、変更の適用をクリックします Apacheモジュールの任意の場所にリンクします。
これらのオプションのほとんどは、仮想サーバーオプションページのディレクトリインデックスアイコンをクリックすることで、仮想サーバー全体に設定できます。この場合、ディレクトリまたはURLの場所のオプションで上書きされない限り、仮想ホストから要求されたすべてのファイルに適用されます。
ディレクトリオプションページには、そのディレクトリ、URLパス、またはファイル名にのみ適用されるオプションを設定するためにクリックできるアイコンが他にもたくさんあります。これらの一部は、エイリアスとリダイレクトなど、この章の後半の他のセクションで説明されています。 および*ディレクトリを保護するパスワード*。
オプションの適用を使用して、設定が適用されるディレクトリ、ファイル名、またはURLの場所を変更できます。 ディレクトリオプションページの下部にあるフォーム。このセクションの冒頭で説明した作成フォームとまったく同じフィールドがあります。変更を加える場合は、[保存]をクリックします button to update the Apache configuration and then the Apply Changes link to make them active. Or to remove the directory configuration and all its options, click on Delete instead.
Creating aliases and redirects
Normally, there is a direct relationship between the path in URL and the file that is returned by the webserver. For example, if a browser requests http://www.example.com/images/foo.gifand the document root for www.example.com is /home/example/www , then the file /home/example/www/images/foo.gif would be read by the webserver and returned to the client.
This can be changed though by using what Apache calls aliases. An alias maps a particular URL path to a file or directory, which does not necessarily have to be under the document root. So in the example above, the /images URL path might actually be aliases to the directory /www/images , which would cause the file /www/images/foo.gif to be read instead.
Aliases can be defined globally or in a virtual server. To create one, the steps to follow are :
- On the module's main page, click on the icon for the virtual server that you want to create the alias under. If you want it to apply to all virtual servers (or you don't have any), click on the *Default Server *icon instead.
- On the virtual server options page that appears, click on the Aliases and Redirects icon. This will take you to the page in the screenshot below.
- Fill in the empty row in the Document directory aliases table with the URL path (under From ) and the file or directory that it should map to (under To )。 If you are editing the default server, there may already be several entries in this table that are part of the standard Apache configuration. There will always be exactly one empty row in the table. If you need to add more than one alias, you will need to re-visit this page after filling in the row and saving.
- 保存をクリックします button to have your new alias stored in the Apache configuration. The browser will return to the virtual server options page.
- To make the alias active, click on the Apply Changes link at the top of the page.
The aliases and redirects form
Existing aliases can be editing by just changing the entries in the Document directory aliases table and then clicking Save 。 You should not change the alias for /icons in the default server though, as this is used by Apache when it generates icons for directory listings. If you want to delete an alias, just delete the contents of both its fields in the table.
Aliases can also be created that use Perl regular expressions to match more complex URL paths. These must be entered into the Regexp document directory aliases table on the Aliases and Redirects form, which has the same columns as the *Document directory aliases* table described above. The difference is that any regular expression can be entered into the From field, such as ^/images/(.*)\.gif$ 。 The To field can taken a string that refers to bracketed sections in the expression, such as /images/$1.jpg 。 This would convert any request for a GIF file into one for the JPEG with the same name.
Redirects are similar to aliases, but have a different purpose and work in a different way. Whenever a client requests a URL path that has been redirected, Apache will tell it to go to another URL (possibly on another server) instead. For example, you might redirect all requests to http://www.example.com/webmin/ to ''http://www.webmin.com/''. Unlike the way aliases behave, if a browser requests a page like /webmin/foo.gif it will not be redirected to ''http://www.webmin.com/foo.gif'' - it will just go to the URL ''http://www.webmin.com/'' instead.
Redirects are implemented by the webserver sending the special 302 status code to the browser, which tells it to go to a new location. It is quite possible for the new URL to be a redirect itself, and you can even create a loop of redirects - not that this is a good idea.
To set up redirection for a path on your server, the steps to follow are :
- On the module's main page, click on the icon for the virtual server that you want to create the redirect under. If you want it to apply to all virtual servers, click on the *Default Server *icon instead.
- On the virtual server options page that appears, click on the Aliases and Redirects icon to go to the page in Figure 29-6.
- In the empty row of the *URL redirects *table, enter the URL path on your server under the From column, such as /webmin 。 Under the To column, enter the URL that requests should be redirected to, such as http://www.webmin.com/ 。 The Status field is optional, but can be filled in if you want to change the HTTP status code that will be used for this redirect. The default is 302, which indicates a temporary redirection. However, you can 301 to tell browsers that the direction is permanent, or 303 to tell them that the original content has been replaced. There will always be exactly one empty row in the table. If you need to add more than one redirect, you will need to re-visit this page after filling in the row and saving.
- 保存をクリックします button to have your new redirect stored in the Apache configuration. The browser will return to the virtual server options page.
- To make the redirection active, click on the Apply Changes link at the top of the page.
As with aliases, existing redirects can be edited by just changing the entries in the URL redirects table and then clicking Save 。 To delete a redirect, just delete the contents of all of its fields in the table.
You can also create regular expression redirects that behave in a similar way to regexp aliases, using the Regexp URL redirects table on the same page. Under the From column you can enter a URL path expression such as ^/webmin/(.*)$ , and under the To column a URL that can refer to bracketed parts of the path, such as http://www.webmin.com/$1 。 In this example, an request by a client for a page under /webmin would be redirected to the same file at www.webmin.com 。
Also on the Aliases and Redirects page are two more tables labelled Permanent URL redirects and Temporary URL redirects 。 The first behaves exactly the same as a normal redirection, but with the status code always set to 301, indicating a permanent redirection. The second also behaves like a normal redirect, but always uses a status code of 302 (temporary redirection). This option is really quite useless, as normal redirections default to using status 302 if one is not specified.
Redirects can also be defined in the options for directories, URL locations, filenames and .htaccess files. When editing the options for one of these (described in the *Setting per-directory options* section), the exact same icon and table are available as when setting up aliases for a virtual server. Naturally, a redirect in a directory only makes sense if the URL path being redirected actually refers to that some file or sub-directory that it contains. The same goes for redirects in URL locations - the path being redirected must start with the location's path.
If Apache on your system has been compiled with or dynamically loads the proxy module (covered in the *Configuring Apache as a proxy server* section below), tables labelled *Map locale to remote URLs* and Map remote Location:headers to local will appear on the Aliases and Redirects form under the virtual server options page. These allow you to specify a URL path that when requested will cause Apache to itself request pages from another website and return them to the browser. Even though the URL that the user is accessing is on your server and their browser is connecting only to your system, the content is actually being loaded from elsewhere.
To set up this URL mapping, the steps to follow are :
- On the module's main page, click on the icon for the virtual server that you want to create the mapping under. If you want it to apply to all virtual servers, click on the *Default Server* icon instead.
- On the virtual server options page that appears, click on the Aliases and Redirects icon to go to the page in Figure 29-6.
- In the empty row in the Map locale to remote URLs table, enter a URL path on your server (like /webmin ) into the first field, and the full URL that you want the pages to be requested from into the second (like http://www.webmin.com/ )。
- In the empty row in the Map remote Location:headers to local table, enter the same full remote URL into the first field and the URL path on your server into the second. This second table controls the conversion of redirects issued by the remote server, and should almost always be set. If it is not set, whenever the remote server issues a redirect the browser will end up connecting directly to it instead of to your server.
- 保存をクリックします button to have your new mapping stored in the Apache configuration. The browser will return to the virtual server options page.
- To make the mapping active, click on the Apply Changes link at the top of the page.
You can test it out by going to the mapped URL path on your system, and you should see pages that have been requested from the remote server. The process is not totally transparent though, because it does not convert HTML files in any way. So if in the example above the remote server contained an HTML page with a link like , following it would take the browser to /foo.html on your system, not /webmin/foo.html as you might expect. There is no solution to this problem, apart from making sure that the remote server always uses relative links and image paths.
Running CGI programs
CGI stands for Common Gateway Interface, and is a standard method for webservers to run external programs, pass them details of a browser's request, and read back any content that the program generates. CGI programs are one of the simplest way of adding dynamic pages to your webserver, and are relatively easy to set up and develop. Server-side includes (covered in the next section) are even simpler, but very limited in what they can do.
A CGI program can be written in any language as long as it follows certain rules. The most common is Perl, but C, Python, PHP or any other language that can access environment variables and produce output can be used. You can even write shell scripts that are valid CGI programs. This section is not going to explain the details of how to write them though - there are plenty of books that cover that already.
CGI programs are just files on your system, like any other HTML or image file. The difference is that when they are requested by a browser, Apache executes them and returns their output instead of the contents of the file. Because you only want this to happen for programs and not for HTML files, the server must be configured to identify certain files as CGI programs. This is normally done in one of two ways - by putting all CGI programs into a certain directory, or by giving them all a file extension like .cgi.
The choice is yours, but the latter option is simpler to use as you can freely mix CGI scripts, HTML and image files in the same directory. To set it up, the steps to follow are :
- On the module's main page, click on the icon for the virtual server that you want to set up CGI programs for. Or click on the *Default Server *icon if you want to use them on all servers.
- Click on the icon for the directory that you want CGI programs to be enabled under. Typically each virtual server will have an icon for options for its document root directory, but if not you can create one by following the steps in the *Setting per-directory options* section above. If you only want to allow CGI programs to be run in some sub-directory of the website, you can create a new directory icon for that as well.
- On the directory options page, click on the Document Options icon and change the Directory options field from Default to Selected below 。 Then set the rows Execute CGI programs and Generate directory indexes はい , and click the Save ページ下部のボタン。 This tells Apache that CGI programs can be executed in the directory.
- Back on the directory options page, click on the MIME Types icon. In the Content handlers table, select cgi-script from the first blank menu under the Handler column, and enter .cgi into the field next to it under the Extensions 桁。 Then click the Save button at the end of the form. This tells Apache to treat all files in the directory ending in .cgi as CGI programs.
- Finally, click the Apply Changes link on any page. You should now be able to create a file with a .cgi extension in the chosen directory, and test it out in a web browser.
An alternative to this approach is to specify a directory in which all files are treated as CGI programs. This has the advantage that they can be given any name you like, instead of being forced to have a .cgi extension. You can also set permissions on this directory to restrict who is allowed to create CGI programs, while still allowing others to edit normal HTML pages.
To set up a directory for CGI scripts, the steps to follow are :
- On the module's main page, click on the icon for the virtual server that you want to set up a CGI directory for. Or click on the *Default Server* icon if you want to set it up for all servers.
- Click on the CGI Programs icon to bring up a page for setting various CGI options.
- The CGI directory aliases table works in a very similar to the Document directory aliases table described in the previous section. However, in addition to mapping a URL path to a directory on your server it also tells Apache that any files accessed through that path should be treated as CGI programs. In the first empty row of the table, enter a URL path like /cgi-bin/ into the From field and a directory like /home/example/cgi-bin/ into the To 分野。
- 保存をクリックします button at the bottom of the page to return to the virtual server options page. Then click the Apply Changes link to make the CGI directory active.
You should now be able to create CGI programs in the directory, and test them out in a web browser. On some Linux distributions, the default Apache configuration will already have a CGI directory available at the URL path /cgi-bin/, mapped to a directory like /home/httpd/cgi-bin/. If this is good enough for you, there is no need to follow the steps above - instead, you can just put CGI programs in that directory.
Normally, all CGI programs execute as the Unix user that the webserver runs as, typically named httpd or apache. On a system with multiple users who cannot be fully trusted, this is not a good thing - anything that one user's CGI program can do, everyone else's can as well. So for example if a user writes a CGI program that edits some file, he would have to make that file writeable by the httpd user, meaning that everyone else's CGI programs could write to it as well.
Fortunately, there is a solution. Apache comes with an optional program called suexec that can be used to have CGI programs run as some other Unix user, rather than as the webserver user. Typically the CGI programs under each virtual server will be run as the Unix user who owns that server's files. To set this up, the steps to follow are :
- Make sure that the suexec program exists on your system, and that it has setuid-root permissions. Apache typically expects to find it in /usr/sbin or /usr/local/apache/sbin, and most Linux distributions include it as a standard part of their Apache package. However, some do not have it setuid by default, so you may need to run chmod 6711 /usr/sbin/suexec to make it so.
- On the main page of the module, click on the icon for the virtual server that you want to have CGI programs run as a different user on. This will take you to the options page shown in Figure 29-4.
- Click on the User and Group icon on the virtual server options page.
- For the Run as Unix user field, select User name and enter the name of the user who owns the virtual server into the field next to it.
- Similarly, for Run as Unix group select Group name and enter the primary group of the user specified in the previous step.
- 保存をクリックします button to return to the options page for the virtual server.
- To activate suexec for the first time, you need to stop and re-start Apache. Use the Stop Apache link at the top of the page to halt it, and then the Start Apache link to start it up again.
- To check that suexec is actually working, check the Apache error log file for a line containing suEXEC mechanism enabled that was logged when the webserver was re-started.
Because it can execute commands as any user on your system, suexec has many security restrictions to prevent misuse by normal users. It will only run CGI programs that are owned by the user and group specified in steps 4 and 5, and only if they are not writeable by any other user, or in a directory that is writeable by another user. The IDs of the user and group must be above minimums that are compiled into the program, to prevent programs owned by system users such as root or bin from being run. Finally, the program must reside under a directory that is compiled into suexec, and nowhere else on the filesystem.
This last restriction can be very annoying if you have a large number of virtual servers and want to enable the execution of CGI programs in their directories. The default allowed directory is typically the standard CGI directory for Apache, such as /home/httpd/cgi-bin. To change this, you will need to re-compile suexec with a different directory, such as /home.
Whenever suexec fails to run a CGI program, it fails with HTTP status code 500. Because there are many things that can go wrong, you should check the file suexec_log in the same directory as the other Apache logfiles to see why it is refusing to execute a particular program. For each failure, a line is written to this file explaining the problem, such as incorrect permissions or a file ownership mismatch.
Writing CGI programs can be difficult because when they fail, very little information is displayed in the browser. All you see is a message like 500 server error , which no explanation of the real cause. However, more detailed error information is written to the Apache error log file. This is usually named error_log, and can be found in the same directory as the Apache access log files. See the section below on Configuring logging for more details on how to find and change it.
Anything that a CGI programs outputs to STDERR will also be written to the error log, which is useful if you want your program to generate debugging information that is not sent to the web browser. Because many programming languages like Perl output error messages on STDERR if a script fails to compile or run, all such messages will also be written to the error log file.
The biggest problem with CGI programs is that the webserver has to launch a new process every time one is requested. If the CGI is written in Perl or PHP, the process then has to load the interpreter for that language which can itself be a large program. The end result is that processing a request for a CGI page takes much longer than a request for a static HTML or image file, and generates much more load on the server system.
For this reason, optional modules have been developed that allow the webserver to run Perl and PHP scripts using an interpreter that is part of the Apache process. These modules are called mod_perl and mod_php, and are included in the Apache package in many Linux distributions. Installing and configuring them is not covered in this chapter though.
Setting up server-side includes
Server-side includes allow you to create simple dynamic web pages without the complexity of writing an entire CGI program in a language like Perl. When active, some of the HTML files served by Apache are checked for special tags starting with appears in the HTML of page, it is replaced with the contents of the file something.html 。
Server-side includes can also be used to access and set environment variables, to conditionally display HTML based on variables and to run CGI programs or shell commands and have their output included in the page. This section will not cover the tags that are available and the purposes though - instead, you should read the documentation on the Apache website or a good book on HTML.
Normally, allowing un-trusted users to create HTML pages containing server-side include tags is perfectly safe because they cannot be used to perform potentially dangerous operations like editing files on the server. The exception to this is the tag, which can be used to run an arbitrary shell command and have its output included in the web page. Because the command runs as the Unix user that Apache is running as (normally httpd), a user who is not allowed to create CGI programs may be able use this kind of tag to read or modify files that he would not normally be able to. For this reason, Apache can be configured to enable server-side includes with or without the risky exec tag.
Because checking an HTML file for server-side include tags is CPU intensive, they are often only activated for files with the .shtml extension. This way you can put static HTML in .html files and dynamic content into .shtml files, so that the server does not have to waste time looking for tags in files that do not contain them. However, it is also quite possible to have all .html files checked for server-side includes if you wish.
To turn on includes for a virtual server, the steps to follow are:
- On the module's main page, click on the icon of the virtual server that you want to enable server-side includes on. Or click on the Default Server icon to enable them for all virtual hosts.
- Click on the icon for the directory that you want server-side includes to be enabled under. Typically each virtual server will have an icon for options for its document root directory, but if not you can create one by following the steps in the *Setting per-directory options* section above. If you only want to enable server-side includes in some sub-directory of the website, you can create a new directory icon for that as well.
- On the directory options page, click on the Document Options icon and change the Directory options field from Default to Selected below 。 If you want to enable server-side includes without the exec tag, change the Server-side includes row to Yes 。 If you want to enable the potentially risky exec tag as well, change Server-side includes and execs row to Yes 代わりは。 Either way, when they have been enabled click the Save ページ下部のボタン。
- Click on the MIME types icon on the directory options page. If you want to enable includes on all HTML files, find the *Content handlers* table to select server-parsed from the first empty menu under the Handler column, and enter .html into the field next to it under the Extensions 桁。 This tells Apache that files ending in .html should be checked for server-side include tags. If you want to enable includes for only .shtml files, enter .shtml instead of .html under the Extensions 桁。 Then in the Extra MIME types table enter text/plain into the first empty field under the Type column and .shtml into the field under Extensions その次。 This tells Apache that .shtml files should be checked for server-side include tags, and that they actually contain HTML.
- Finally, click the Save button at the bottom of the MIME Types page, and then the Apply Changes link back on the directory options page.
Once server-side includes are enabled, you can test them by creating an .html or .shtml file in the chosen directory with some special tags it in. Then open the page in your web browser to see the result. If for some reason server-side includes were not enabled properly, nothing will show up at all because the