Apache2 をインストールした後、apachectl と httpd を最大限に活用したい場合は、それ以上のことを行う必要があります。開始、停止、再起動を使用します。この記事で提供する 9 つの実用的な例は、apachectl と httpd を非常に効果的に使用するのに役立ちます。
Apachectl は SysV init スクリプトとして機能し、start、stop、restart、status などの引数を取ります。また、コマンドライン引数を httpd に渡すだけで、httpd コマンドのフロントエンドとしても機能します。したがって、apachectl を使用して実行するすべてのコマンドは、httpd を呼び出して直接実行することもできます。
1.別の httpd.conf ファイル名を apachectl に渡します
通常、元の httpd.conf を変更して、さまざまな Apache ディレクティブを試します。何かがうまくいかない場合は、変更を元に戻します。元の httpd.conf をいじる代わりに、それを新しい httpd.conf.debug にコピーし、この新しい httpd.conf.debug ファイルを Apache でテスト目的で使用します (オプション -f を使用)。
# apachectl -f conf/httpd.conf.debug # httpd -k start -f conf/httpd.conf.debug [Note: you can use either apachectl or httpd as shown above] # ps -ef | grep http root 25080 1 0 23:26 00:00:00 /usr/sbin/httpd -f conf/httpd.conf.debug apache 25099 25080 0 23:28 00:00:00 /usr/sbin/httpd -f conf/httpd.conf.debug [Note: ps shows the httpd running with httpd.conf.debug file]
変更に満足し、Apache が httpd.conf.debug で問題なく実行されたら、変更を httpd.conf にコピーして、以下に示すように Apache を通常どおり起動できます。
# cp httpd.conf.debug httpd.conf # apachectl stop # apachectl start # ps -ef | grep httpd root 25114 1 0 23:28 00:00:00 /usr/sbin/httpd -k start daemon 25115 25114 0 23:28 00:00:00 /usr/sbin/httpd -k start [Note: ps indicates that the httpd is running using the default config file]
2. httpd.conf を変更せずに一時的な DocumentRoot を使用する
これは、Web サイトの別のレイアウトを試していて、デフォルトの DocumentRoot の下にある元のファイルを変更したくない場合に非常に役立ちます。元の DocumentRoot ディレクトリ (/var/www/html) のコピーを、新しい一時 DocumentRoot ディレクトリ (/var/www/html_debug) にコピーします。この一時 DocumentRoot ディレクトリ (/var/www/html_debug) の下ですべての変更を行い、オプション -c を使用して以下に示すように、この一時ディレクトリで Apache を起動します。
# httpd -k start -c "DocumentRoot /var/www/html_debug/"
デフォルトの DocumentRoot (/var/www/html) を使用して元の構成に戻したい場合は、以下に示すように Apache を再起動するだけです。
# httpd -k stop # apachectl start
3. LogLevel を一時的に増やします
問題をデバッグしている間、オプション -e を使用して以下に示すように、httpd.conf の LogLevel ディレクティブを変更せずに、Apache の LogLevel を一時的に変更できます。この例では、LogLevel は debug に設定されています。
# httpd -k start -e debug [Sun Aug 17 13:53:06 2008] [debug] mod_so.c(246): loaded module auth_basic_module [Sun Aug 17 13:53:06 2008] [debug] mod_so.c(246): loaded module auth_digest_module
option -e に渡すことができる値 :debug、info、notice、warn、error、crit、alert、emerg
4.オプション -l を使用して Apache 内でコンパイルされたモジュールを表示します
# httpd -l Compiled in modules: core.c prefork.c http_core.c mod_so.c
5. Apache によってロードされた静的モジュールと動的モジュールの両方を表示
オプション -l を httpd に渡すと、静的モジュールのみが表示されます。オプション -M を渡すと、以下に示すように静的モジュールと共有モジュールの両方が表示されます。
# httpd -M Loaded Modules: core_module (static) mpm_prefork_module (static) http_module (static) so_module (static) auth_basic_module (shared) auth_digest_module (shared) authn_file_module (shared) authn_alias_module (shared) Syntax OK
6. httpd.conf 内のすべての受け入れられたディレクティブを表示します
これは httpd の拡張ヘルプのようなもので、すべての httpd.conf ディレクティブとそれらが有効な場所を表示します。特定のディレクティブについて、すべての可能な値と、httpd.conf 内で使用できる場所を示します。これは、特定の Apache ディレクティブについてすばやく知りたい場合に非常に役立ちます。
# httpd -L HostnameLookups (core.c) "on" to enable, "off" to disable reverse DNS lookups, or "double" to enable double-reverse DNS lookups Allowed in *.conf anywhere ServerLimit (prefork.c) Maximum value of MaxClients for this run of Apache Allowed in *.conf only outside <Directory>, <Files> or <Location> KeepAlive (http_core.c) Whether persistent connections should be On or Off Allowed in *.conf only outside <Directory>, <Files> or <Location> LoadModule (mod_so.c) a module name and the name of a shared object file to load it from Allowed in *.conf only outside <Directory>, <Files> or <Location>
7.変更後に httpd.conf を検証する
オプション -t を使用して、特定の Apache 構成ファイルに問題があるかどうかを検証します。以下の例では、httpd.conf.debug の 148 行目に問題があることを示しています。 mod_auth_basicso に . (ピリオド) so の前。
# httpd -t -f conf/httpd.conf.debug httpd: Syntax error on line 148 of /etc/httpd/conf/httpd.conf.debug: Cannot load /etc/httpd/modules/mod_auth_basicso into server: /etc/httpd/modules/mod_auth_basicso: cannot open shared object file: No such file or directory
問題を修正すると、Syntax OK と表示されます .
# httpd -t -f conf/httpd.conf.debug Syntax OK
8. httpd ビルド パラメータを表示する
オプション -V (大文字の V) を使用して、Apache のバージョン番号と、Apache のビルド中に使用されるすべてのパラメーターを表示します。
# httpd -V Server version: Apache/2.2.9 (Unix) Server built: Jul 14 2008 15:36:56 Server's Module Magic Number: 20051115:15 Server loaded: APR 1.2.12, APR-Util 1.2.12 Compiled using: APR 1.2.12, APR-Util 1.2.12 Architecture: 32-bit Server MPM: Prefork threaded: no forked: yes (variable process count) Server compiled with.... -D APACHE_MPM_DIR="server/mpm/prefork" -D APR_HAS_SENDFILE -D APR_HAS_MMAP -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled) -D APR_USE_SYSVSEM_SERIALIZE -D APR_USE_PTHREAD_SERIALIZE -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT -D APR_HAS_OTHER_CHILD -D AP_HAVE_RELIABLE_PIPED_LOGS -D DYNAMIC_MODULE_LIMIT=128 -D HTTPD_ROOT="/etc/httpd" -D SUEXEC_BIN="/usr/sbin/suexec" -D DEFAULT_PIDLOG="logs/httpd.pid" -D DEFAULT_SCOREBOARD="logs/apache_runtime_status" -D DEFAULT_LOCKFILE="logs/accept.lock" -D DEFAULT_ERRORLOG="logs/error_log" -D AP_TYPES_CONFIG_FILE="conf/mime.types" -D SERVER_CONFIG_FILE="conf/httpd.conf"
Apache のバージョン番号のみを表示する場合は、以下に示すようにオプション -v (小文字の v) を使用します。
# httpd -v Server version: Apache/2.2.9 (Unix) Server built: Jul 14 2008 15:36:56
9.オンデマンドでのみ特定のモジュールをロードします。
場合によっては、Apache にすべてのモジュールをロードしたくない場合があります。たとえば、 LDAP をテストする場合にのみ、LDAP 関連のモジュールを Apache にロードすることができます。これは、以下に示すように実現できます。
httpd.conf を変更して IfDefine を追加します load-ldap というディレクティブ (これには任意の名前を付けることができます)。
<IfDefine load-ldap> LoadModule ldap_module modules/mod_ldap.so LoadModule authnz_ldap_module modules/mod_authnz_ldap.so </IfDefine>
LDAP をテストしていて、LDAP 関連のモジュールをロードしたい場合は、以下に示すように、load-ldap を Option -D に渡します。
# httpd -k start -e debug -Dload-ldap -f /etc/httpd/conf/httpd.conf.debug [Sun Aug 17 14:14:58 2008] [debug] mod_so.c(246): loaded module ldap_module [Sun Aug 17 14:14:58 2008] [debug] mod_so.c(246): loaded module authnz_ldap_module [Note: Pass -Dload-ldap, to load the ldap modules into Apache] # apachectl start [Note: Start the Apache normally, if you don't want to load the ldap modules.]
この記事が気に入ったら、del.icio.us、Digg and Stumble でブックマークしてください 以下の「次は?」セクションにあるリンクを使用してください。