覚えておくと便利なApacheの調査方法

初めてログインしてみるサーバはどんな設定になってるの?


最近、サーバ移行の仕事があったので、そのとき便利だったコマンド。

まずは、httpdの実体の場所を調べる。

ps alxw | grep httpd
0   500  6777  5952  18   0   4992   752 -      R+   pts/0      0:00 grep httpd
5     0 15447     1  18   0 156168 11248 -      Ss   ?          0:15 /usr/local/apache2/bin/httpd
5   501 17106 15447  16   0 156168  8320 -      S    ?          0:00 /usr/local/apache2/bin/httpd
5   501 17107 15447  16   0 156168  8320 -      S    ?          0:00 /usr/local/apache2/bin/httpd
5   501 17108 15447  16   0 156168  8320 -      S    ?          0:00 /usr/local/apache2/bin/httpd
5   501 17109 15447  19   0 156168  8320 -      S    ?          0:00 /usr/local/apache2/bin/httpd
5   501 17124 15447  19   0 156168  8320 -      S    ?          0:00 /usr/local/apache2/bin/httpd

/usr/local/apache2/bin/httpd
これで、動いている場所ゲット。

次に動作させてるIPやポート、バーチャルドメイン、その設定場所を調べる

httpdの場所は「/usr/local/apache2/bin/httpd」と分かったので、

/usr/local/apache2/bin/httpd -S -DSSL
VirtualHost configuration:
xxx.xxx.xxx.xxx:80     is a NameVirtualHost
         default server www.hogehoge.jp (/usr/local/apache2/conf/extra/httpd-vhosts.conf:48)
         port 80 namevhost www.hogehoge.jp (/usr/local/apache2/conf/extra/httpd-vhosts.conf:48)
         port 80 namevhost dev.hogehoge.jp (/usr/local/apache2/conf/extra/httpd-vhosts.conf:121)
xxx.xxx.xxx.xxx:443    www.hogehoge.jp (/usr/local/apache2/conf/ssl.conf:185)
Syntax OK

これで、設定ファイルの場所、動いてるIP、ドメインをゲット。

  • -DSSLをつけると、httpsの情報も分かる。
  • xxx.xxx.xxx.xxxの部分はIP。*だったら、IPを指定して動かしてない。
  • :80やら:443はApacheが動くポート番号。
  • defaultはデフォルトで動くバーチャルホスト。


リクエストが来ると、サーバはまず最初に にマッチする IP アドレスかどうかをチェックします。マッチすれば マッチした IP アドレスの のそれぞれのセクションの中から ServerName か ServerAlias に要求されたホスト名があるか探します。 見つかればそのサーバ用の設定を使います。マッチするバーチャルホスト が見つからなければ、マッチした IP アドレスの リストの最初にあるバーチャルホスト が使われます。

リライトやWebDAVが使えるかどうか。→ロードされてるモジュールを調べる

/usr/local/apache2/bin/httpd -M
Loaded Modules:
 core_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 authn_file_module (shared)
 authn_dbm_module (shared)
 authn_anon_module (shared)
 authn_dbd_module (shared)
 authn_default_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_dbm_module (shared)
 authz_owner_module (shared)
 authz_default_module (shared)
 auth_basic_module (shared)
 auth_digest_module (shared)
 dbd_module (shared)
 dumpio_module (shared)
 ext_filter_module (shared)
 include_module (shared)
 filter_module (shared)
 substitute_module (shared)
 deflate_module (shared)
 log_config_module (shared)
 logio_module (shared)
 env_module (shared)
 expires_module (shared)
 headers_module (shared)
 ident_module (shared)
 setenvif_module (shared)
 ssl_module (shared)
 mime_module (shared)
 dav_module (shared)
 status_module (shared)
 autoindex_module (shared)
 asis_module (shared)
 info_module (shared)
 cgi_module (shared)
 dav_fs_module (shared)
 vhost_alias_module (shared)
 negotiation_module (shared)
 dir_module (shared)
 imagemap_module (shared)
 actions_module (shared)
 speling_module (shared)
 userdir_module (shared)
 alias_module (shared)
 rewrite_module (shared)
 php5_module (shared)
Syntax OK
  • (static)は静的にコンパイル時に組み込んだモジュールで、(shared)はApache起動時に読み込む動的共有オブジェクト (DSO)。so_moduleがあれば、DSOであとからいろいろモジュールを組み込める。

アーキテクチャやMPMなど、コンパイル時の設定を調べる

/usr/local/apache2/bin/httpd -V
Server version: Apache/2.2.11 (Unix)
Server built:   Jan 14 2009 16:42:26
Server's Module Magic Number: 20051115:21
Server loaded:  APR 1.3.3, APR-Util 1.3.4
Compiled using: APR 1.3.3, APR-Util 1.3.4
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="/usr/local/apache2"
 -D SUEXEC_BIN="/usr/local/apache2/bin/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"


httpd.confとか見なくてもサクッとhttpd -S -DSSLで見れるのはとても便利だなー。