Apacheのモジュール一覧を調べてみた

2022年6月17日

前提

書くこと/書かないこと

Apacheをソースインストールしようとしたときに、どのモジュールを有効にしていいかわからなかったので調べた結果を記載します。

ついでに、インストールと設定方法によってメモリ使用量がどのように変わるのかも調べましたので後段に記載しています。

環境

Apache 2.4 ※CentOS8代替OS

さくっと

内容的にさくっとまとめるのが難しいので後回しにします。

こってりと

背景

Apacheのモジュールには、コンパイル時に組み込まれている静的オブジェクトと取り外し自由な状態でインストールされる動的共有オブジェクト(DSO)の2種類が存在します。

dnfなどのパッケージ管理システムからApacheをインストールすると、様々な動的共有オブジェクト(DSO)が自動的にインストールされ、その一部が有効になります。

他方で、Apacheをソースコードからインストールする場合、enableで必要なDSOを指定するか、enable_shared_modsでfew, most, all, reallyallのいずれかを指定することで、事前にグルーピングされたDSOを一括でインストールすることができ、その一部が有効になります。何も指定しなかった場合はenable_shared_modsのデフォルト値であるallが指定されたものとみなされてモジュールがインストールされます。

ここまではわかりやすいのですが、DSOの全体像を知りたかったのと、各条件で何がインストールされ、何が有効になるのかがわからなかったので、実験して調べてみました。

調査結果

過程は地味すぎるので結果だけ書きます。
調査したバージョンは下記です。バージョンは揃えるべきでした。。。

AlmaLinux release 8.6 (Sky Tiger)
dnf: Server version: Apache/2.4.37 (AlmaLinux)
ソースインストール: Server version: Apache/2.4.53 (Unix)

インストールされるモジュール

まずは有効かどうかは置いといて、インストールされるモジュールの違いから。
これはhttpd/modulesの中に存在するmod_で始まるファイルを調べました。
モジュールの全量はApacheの公式サイトを参考にしています。

https://httpd.apache.org/docs/2.4/en/mod/

結果は末尾に合計数を集計していますが、ソースインストールのデフォルトであるallとdnfも一致せず、公式サイトで説明されているモジュールのステータスとも明確な関係は確認できませんでした。なお、ソースインストールでreallyallを指定した場合のみ、公式サイトに記載がないモジュールが8つインストールされました。逆に9つのモジュールは、どのインストール方法でもインストールされませんでした。

モジュールステータスdnffewmostallreallyall備考
mod_access_compatExtensionYYYYY
mod_actionsBaseYYYY
mod_aliasBaseYYYYY
mod_allowmethodsExperimentalYYYY
mod_asisBaseYYY
mod_auth_basicBaseYYYYY
mod_auth_digestExtensionYYYY
mod_auth_formBaseYYY
mod_authn_anonExtensionYYYY
mod_authn_coreBaseYYYYY
mod_authn_dbdExtensionYYYY
mod_authn_dbmExtensionYYYY
mod_authn_fileBaseYYYYY
mod_authn_socacheBaseYYYY
mod_authnz_fcgiExtensionY
mod_authnz_ldapExtensionいずれも存在しない
mod_authz_coreBaseYYYYY
mod_authz_dbdExtensionYYYY
mod_authz_dbmExtensionYYYY
mod_authz_groupfileBaseYYYYY
mod_authz_hostBaseYYYYY
mod_authz_ownerExtensionYYYY
mod_authz_userBaseYYYYY
mod_autoindexBaseYYYYY
mod_brotliExtensionY
mod_bucketeerY公式サイトに記載なし
mod_bufferExtensionYYYY
mod_cacheExtensionYYYY
mod_cache_diskExtensionYYYY
mod_cache_socacheExtensionYYYY
mod_case_filterY公式サイトに記載なし
mod_case_filter_inY公式サイトに記載なし
mod_cern_metaExtensionY
mod_cgiBaseYY
mod_cgidBaseYYYY
mod_charset_liteExtensionYYY
mod_dataExtensionYYY
mod_davExtensionYYYY
mod_dav_fsExtensionYYYY
mod_dav_lockExtensionYYY
mod_dbdExtensionYYYY
mod_deflateExtensionYYYY
mod_dialupExperimentalYYY
mod_dirBaseYYYYY
mod_dumpioExtensionYYYY
mod_echoExperimentalYYY
mod_envBaseYYYYY
mod_example_hooksExperimentalY
mod_example_ipcY公式サイトに記載なし
mod_expiresExtensionYYYY
mod_ext_filterExtensionYYYY
mod_file_cacheExperimentalYYY
mod_filterBaseYYYYY
mod_headersExtensionYYYYY
mod_heartbeatExperimentalYYY
mod_heartmonitorExperimentalYYY
mod_http2ExtensionY
mod_identExtensionY
mod_imagemapBaseY
mod_includeBaseYYYY
mod_infoExtensionYYYY
mod_isapiBaseY
mod_lbmethod_bybusynessExtensionYYYY
mod_lbmethod_byrequestsExtensionYYYY
mod_lbmethod_bytrafficExtensionYYYY
mod_lbmethod_heartbeatExperimentalYYYY
mod_ldapExtensionいずれも存在しない
mod_log_configBaseYYYYY
mod_log_debugExperimentalYYYY
mod_log_forensicExtensionYYY
mod_logioExtensionYYYY
mod_luaExtensionY
mod_macroBaseYYYY
mod_mdExperimentalいずれも存在しない
mod_mimeBaseYYYYY
mod_mime_magicExtensionYYY
mod_negotiationBaseYYYY
mod_nw_sslBaseいずれも存在しない
mod_optional_fn_exportY公式サイトに記載なし
mod_optional_fn_importY公式サイトに記載なし
mod_optional_hook_exportY公式サイトに記載なし
mod_optional_hook_importY公式サイトに記載なし
mod_privilegesExperimentalいずれも存在しない
mod_proxyExtensionYYYY
mod_proxy_ajpExtensionYYYY
mod_proxy_balancerExtensionYYYY
mod_proxy_connectExtensionYYYY
mod_proxy_expressExtensionYYYY
mod_proxy_fcgiExtensionYYYY
mod_proxy_fdpassExtensionYYYY
mod_proxy_ftpExtensionYYYY
mod_proxy_hcheckExtensionYYYY
mod_proxy_htmlBaseいずれも存在しない
mod_proxy_httpExtensionYYYY
mod_proxy_http2ExtensionYY
mod_proxy_scgiExtensionYYYY
mod_proxy_uwsgiExtensionYYYY
mod_proxy_wstunnelExtensionYYYY
mod_ratelimitExtensionYYYY
mod_reflectorBaseYYY
mod_remoteipBaseYYYY
mod_reqtimeoutExtensionYYYYY
mod_requestBaseYYYY
mod_rewriteExtensionYYYY
mod_sedExperimentalYYYY
mod_sessionExtensionYYY
mod_session_cookieExtensionYYY
mod_session_cryptoExperimentalいずれも存在しない
mod_session_dbdExtensionYYY
mod_setenvifBaseYYYYY
mod_slotmem_plainExtensionYYY
mod_slotmem_shmExtensionYYYY
mod_soExtensionいずれもstaticとしてインストール
mod_socache_dbmExtensionYYYY
mod_socache_dcExtensionいずれも存在しない
mod_socache_memcacheExtensionYYYY
mod_socache_redisExtensionYYY
mod_socache_shmcbExtensionYYYY
mod_spelingExtensionYYYY
mod_sslExtensionY
mod_statusBaseYYYYY
mod_substituteExtensionYYYY
mod_suexecExtensionYY
mod_systemdExtensionY
mod_tlsExperimentalいずれも存在しない
mod_unique_idExtensionYYYY
mod_unixdBaseYYYYY
mod_userdirBaseYYYY
mod_usertrackExtensionYYY
mod_versionExtensionYYYYY
mod_vhost_aliasExtensionYYYY
mod_watchdogBaseYYYY
mod_xml2encBaseY
合計1022187100118

有効化されるモジュール

次は、上記のインストール結果を前提に、初期状態で有効になっているモジュールを調べました。
こちらはコマンド"httpd -M"の実行結果から取得しました。

モジュールステータスdnffewmostallreallyall備考
mod_access_compatExtensionYYYYY
mod_actionsBaseY
mod_aliasBaseYYYYY
mod_allowmethodsExperimentalY
mod_auth_basicBaseYYYYY
mod_auth_digestExtensionY
mod_authn_anonExtensionY
mod_authn_coreBaseYYYYY
mod_authn_dbdExtensionY
mod_authn_dbmExtensionY
mod_authn_fileBaseYYYYY
mod_authn_socacheBaseY
mod_authz_coreBaseYYYYY
mod_authz_dbdExtensionY
mod_authz_dbmExtensionY
mod_authz_groupfileBaseYYYYY
mod_authz_hostBaseYYYYY
mod_authz_ownerExtensionY
mod_authz_userBaseYYYYY
mod_autoindexBaseYYYYY
mod_brotliExtensionY
mod_cacheExtensionY
mod_cache_diskExtensionY
mod_cache_socacheExtensionY
mod_dataExtensionY
mod_dbdExtensionY
mod_deflateExtensionY
mod_dirBaseYYYYY
mod_dumpioExtensionY
mod_echoExperimentalY
mod_envBaseYYYYY
mod_expiresExtensionY
mod_ext_filterExtensionY
mod_filterBaseYYYYY
mod_headersExtensionYYYYY
mod_http2ExtensionY
mod_includeBaseY
mod_infoExtensionY
mod_lbmethod_bybusynessExtensionY
mod_lbmethod_byrequestsExtensionY
mod_lbmethod_bytrafficExtensionY
mod_lbmethod_heartbeatExperimentalY
mod_log_configBaseYYYYY
mod_logioExtensionY
mod_macroBaseY
mod_mimeBaseYYYYY
mod_mime_magicExtensionY
mod_negotiationBaseY
mod_proxyExtensionY
mod_proxy_ajpExtensionY
mod_proxy_balancerExtensionY
mod_proxy_connectExtensionY
mod_proxy_expressExtensionY
mod_proxy_fcgiExtensionY
mod_proxy_fdpassExtensionY
mod_proxy_ftpExtensionY
mod_proxy_hcheckExtensionY
mod_proxy_httpExtensionY
mod_proxy_http2ExtensionY
mod_proxy_scgiExtensionY
mod_proxy_uwsgiExtensionY
mod_proxy_wstunnelExtensionY
mod_remoteipBaseY
mod_reqtimeoutExtensionYYYYY
mod_requestBaseY
mod_rewriteExtensionY
mod_setenvifBaseYYYYY
mod_slotmem_plainExtensionY
mod_slotmem_shmExtensionY
mod_socache_dbmExtensionY
mod_socache_memcacheExtensionY
mod_socache_shmcbExtensionY
mod_sslExtensionY
mod_statusBaseYYYYY
mod_substituteExtensionY
mod_suexecExtensionY
mod_systemdExtensionY
mod_unique_idExtensionY
mod_unixdBaseYYYYY
mod_userdirBaseY
mod_versionExtensionYYYYY
mod_vhost_aliasExtensionY
mod_watchdogBaseY
合計8321212121

ソースインストールの場合、有効化されるモジュールはenable-mods-sharedの指定に関わらず同じで、パッケージインストールに比べると約1/4程度の少数のモジュールだけが有効になっていました。

メモリ使用量を比べる

インストールされたモジュールと有効化されたモジュールの違いによってApacheが使用するメモリにどの程度差が出るのかどうか調べてみました。

まず、公式サイトには下記の記述があり、意訳すると、モジュールはロードされない限りメモリを消費しないと書いてあります。

The executable program has to manually resolve every symbol it needs to be able to use it. The advantage of such a mechanism is that optional program parts need not be loaded (and thus do not spend memory) until they are needed by the program in question. When required, these program parts can be loaded dynamically to extend the base program’s functionality.

https://httpd.apache.org/docs/current/en/dso.html

調査方法ですが、dnf, few, most, all, reallyallのそれぞれについて、Apacheを起動した直後のメモリ使用量を下記のコマンド(先人の知恵をお借りしました)で調べました。
実行ユーザ"apache"で起動している"httpd"のプロセス(=httpdの子プロセス)を対象に、メモリ使用量合計、プロセス数、平均使用量を表示するものです。

ps aux | grep httpd | grep apache | awk '{print $6}' | awk '{sum=sum+($1/1024);cnt++;} END{print "sum="sum " cnt="cnt " ave="sum/cnt;}'

結果は下記となります。

ケースインストールモジュール数有効モジュール数メモリ使用量合計(MB)プロセス数プロセス当たり
平均使用量(MB)
dnf1028337.3438312.4479
few212120.742236.91406
most872120.718836.90625
all1002120.929736.97656
reallyall1182120.613336.87109
reallyall
(全モジュール有効化)
118117
(*1)
43.39064
(*2)
10.8477
*1 MPMがPreforkの場合はmod_cgiが、その他の場合はmod_cgidが有効になるようで、全部有効にはできませんでした。
*2 どのモジュールが作用しているかはわかっていませんが、起動直後のプロセス数が1つ増えました。

プロセス当たりの平均使用量を見ると、公式サイトの説明通り、有効モジュール数が多いdnfが大きく、有効モジュール数が同じfew~reallallは概ね同程度となっていることが確認できました。

比較のため、reallyallのケースにおいて、デフォルトのhttpd.confでコメントアウトされているLoadModuleを全部有効化した場合も確認すると、有効化前と比べて明らかに使用量が増えることが確認できました。

メモリ使用量はあくまで今回の実験結果の一例であり、再起動するごとに若干の誤差が出るため、値自体は参考程度とご理解頂きたいですが、必要なモジュール以外は無効にすることで、メモリ使用量を抑えることができることがわかりました。不要なモジュールを組み込んでおくことはセキュリティリスクになることもあるので、モジュールの精査は大事ですね。

(参考)Apacheモジュール一覧と機能説明

公式サイトにモジュール一覧とその説明があるので記載しておきます。

https://httpd.apache.org/docs/current/mod/

モジュールステータス説明
mod_access_compatExtensionホスト (名前もしくは IP アドレス) に基づいたグループ承認
mod_actionsBaseメディアタイプやリクエストメソッドに応じて CGI スクリプトを実行する機能を提供
mod_aliasBaseホストファイルシステム上のいろいろな違う場所を ドキュメントツリーにマップする機能と、 URL のリダイレクトを行なう機能を提供する
mod_allowmethodsExperimentalEasily restrict what HTTP methods can be used on the server
mod_asisBase自分用の HTTP ヘッダの書かれているファイルを送信する
mod_auth_basicBase基本認証
mod_auth_digestExtensionUser authentication using MD5 Digest Authentication
mod_auth_formBaseForm authentication
mod_authn_anonExtension認証が必要な領域への “anonymous" ユーザのアクセスを許可する
mod_authn_coreBaseCore Authentication
mod_authn_dbdExtensionUser authentication using an SQL database
mod_authn_dbmExtensionDBM ファイルを用いたユーザ認証
mod_authn_fileBaseテキストファイルを用いたユーザ認証
mod_authn_socacheBaseManages a cache of authentication credentials to relieve the load on backends
mod_authnz_fcgiExtensionAllows a FastCGI authorizer application to handle Apache httpd authentication and authorization
mod_authnz_ldapExtensionAllows an LDAP directory to be used to store the database for HTTP Basic authentication.
mod_authz_coreBaseCore Authorization
mod_authz_dbdExtensionGroup Authorization and Login using SQL
mod_authz_dbmExtensionGroup authorization using DBM files
mod_authz_groupfileBaseプレーンテキストファイルを用いたグループ承認
mod_authz_hostBaseGroup authorizations based on host (name or IP address)
mod_authz_ownerExtensionファイルの所有者に基づいた承認
mod_authz_userBaseユーザ承認
mod_autoindexBaseUnix の ls コマンドや Win32 の dir シェルコマンドに似た ディレクトリインデックスを生成する
mod_brotliExtensionCompress content via Brotli before it is delivered to the client
mod_bucketeer公式サイトに記載なし
mod_bufferExtensionSupport for request buffering
mod_cacheExtensionURI をキーにしたコンテンツのキャッシュ
mod_cache_diskExtensionURI をキーにしたコンテンツキャッシュストレージ管理
mod_cache_socacheExtensionShared object cache (socache) based storage module for the HTTP caching filter.
mod_case_filter公式サイトに記載なし
mod_case_filter_in公式サイトに記載なし
mod_cern_metaExtensionCERN httpd metafile semantics
mod_cgiBaseCGI スクリプトの実行
mod_cgidBase外部 CGI デーモンを使った CGI スクリプトの実行
mod_charset_liteExtensionSpecify character set translation or recoding
mod_dataExtensionConvert response body into an RFC2397 data URL
mod_davExtension分散オーサリングとバージョン管理 (WebDAV) 機能
mod_dav_fsExtensionmod_dav のためのファイルシステムプロバイダ
mod_dav_lockExtensionmod_dav 用の汎用ロックモジュール
mod_dbdExtensionManages SQL database connections
mod_deflateExtensionクライアントへ送られる前にコンテンツを圧縮する
mod_dialupExperimentalSend static content at a bandwidth rate limit, defined by the various old modem standards
mod_dirBase「最後のスラッシュ」のリダイレクトと、ディレクトリの インデックスファイルを扱う機能を提供する
mod_dumpioExtension望むようにすべての I/O をエラーログにダンプする
mod_echoExperimentalプロトコルモジュールの概要を示すための単純なエコーサーバ
mod_envBaseCGI スクリプト及び SSI ページに渡される環境変数を変更する機能を提供する
mod_example_hooksExperimentalIllustrates the Apache module API
mod_example_ipc公式サイトに記載なし
mod_expiresExtensionユーザの指定した基準に基づいた Expires と Cache-Control HTTP ヘッダの生成
mod_ext_filterExtensionレスポンスのボディをクライアントに送る前に外部プログラムで処理する
mod_file_cacheExperimentalCaches a static list of files in memory
mod_filterBaseContext-sensitive smart filter configuration module
mod_headersExtensionHTTP リクエストのヘッダと応答のヘッダのカスタマイズ
mod_heartbeatExperimentalSends messages with server status to frontend proxy
mod_heartmonitorExperimentalCentralized monitor for mod_heartbeat origin servers
mod_http2ExtensionSupport for the HTTP/2 transport layer
mod_identExtensionRFC 1413 ident lookups
mod_imagemapBaseServer-side imagemap processing
mod_includeBaseサーバがパースする html ドキュメント (Server Side Includes)
mod_infoExtensionサーバの設定の包括的な概観を提供する
mod_isapiBaseISAPI Extensions within Apache for Windows
mod_lbmethod_bybusynessExtensionPending Request Counting load balancer scheduler algorithm for mod_proxy_balancer
mod_lbmethod_byrequestsExtensionRequest Counting load balancer scheduler algorithm for mod_proxy_balancer
mod_lbmethod_bytrafficExtensionWeighted Traffic Counting load balancer scheduler algorithm for mod_proxy_balancer
mod_lbmethod_heartbeatExperimentalHeartbeat Traffic Counting load balancer scheduler algorithm for mod_proxy_balancer
mod_ldapExtensionLDAP connection pooling and result caching services for use by other LDAP modules
mod_log_configBaseサーバへのリクエストのロギング
mod_log_debugExperimentalAdditional configurable debug logging
mod_log_forensicExtensionサーバに送られたリクエストの forensic ロギング
mod_logioExtensionリクエスト毎に入力バイト数と出力バイト数とをロギング
mod_luaExtensionProvides Lua hooks into various portions of the httpd request processing
mod_macroBaseProvides macros within apache httpd runtime configuration files
mod_mdExperimentalManaging domains across virtual hosts, certificate provisioning via the ACME protocol
mod_mimeBaseリクエストされたファイルの拡張子とファイルの振る舞い (ハンドラとフィルタ)、内容 (MIME タイプ、言語、文字セット、エンコーディング) とを関連付ける
mod_mime_magicExtensionDetermines the MIME type of a file by looking at a few bytes of its contents
mod_negotiationBaseコンテントネゴシエーション 機能を提供する
mod_nw_sslBaseEnable SSL encryption for NetWare
mod_optional_fn_export公式サイトに記載なし
mod_optional_fn_import公式サイトに記載なし
mod_optional_hook_export公式サイトに記載なし
mod_optional_hook_import公式サイトに記載なし
mod_privilegesExperimentalSupport for Solaris privileges and for running virtual hosts under different user IDs.
mod_proxyExtensionHTTP/1.1 プロキシ/ゲートウェイサーバ
mod_proxy_ajpExtensionmod_proxy で AJP をサポートするためのモジュール
mod_proxy_balancerExtension負荷分散のための mod_proxy 拡張
mod_proxy_connectExtensionCONNECT リクエストを扱う mod_proxy 用の拡張
mod_proxy_expressExtensionDynamic mass reverse proxy extension for mod_proxy
mod_proxy_fcgiExtensionFastCGI support module for mod_proxy
mod_proxy_fdpassExtensionfdpass external process support module for mod_proxy
mod_proxy_ftpExtensionFTP support module for mod_proxy
mod_proxy_hcheckExtensionDynamic health check of Balancer members (workers) for mod_proxy
mod_proxy_htmlBaseRewrite HTML links in to ensure they are addressable from Clients’ networks in a proxy context.
mod_proxy_httpExtensionHTTP support module for mod_proxy
mod_proxy_http2ExtensionHTTP/2 support module for mod_proxy
mod_proxy_scgiExtensionSCGI gateway module for mod_proxy
mod_proxy_uwsgiExtensionUWSGI gateway module for mod_proxy
mod_proxy_wstunnelExtensionWebsockets support module for mod_proxy
mod_ratelimitExtensionBandwidth Rate Limiting for Clients
mod_reflectorBaseReflect a request body as a response via the output filter stack.
mod_remoteipBaseReplaces the original client IP address for the connection with the useragent IP address list presented by a proxies or a load balancer via the request headers.
mod_reqtimeoutExtensionSet timeout and minimum data rate for receiving requests
mod_requestBaseFilters to handle and make available HTTP request bodies
mod_rewriteExtensionProvides a rule-based rewriting engine to rewrite requested URLs on the fly
mod_sedExperimentalFilter Input (request) and Output (response) content using sed syntax
mod_sessionExtensionSession support
mod_session_cookieExtensionCookie based session support
mod_session_cryptoExperimentalSession encryption support
mod_session_dbdExtensionDBD/SQL based session support
mod_setenvifBaseリクエストの特徴に基づいた環境変数の設定を可能にする
mod_slotmem_plainExtensionSlot-based shared memory provider.
mod_slotmem_shmExtensionSlot-based shared memory provider.
mod_soExtension起動時や再起動時に実行コードとモジュールをサーバにロードする
mod_socache_dbmExtensionDBM based shared object cache provider.
mod_socache_dcExtensionDistcache based shared object cache provider.
mod_socache_memcacheExtensionMemcache based shared object cache provider.
mod_socache_redisExtensionRedis based shared object cache provider.
mod_socache_shmcbExtensionshmcb based shared object cache provider.
mod_spelingExtensionユーザが入力したであろう間違った URL を、 大文字小文字の区別を無視することと一つ以下の綴り間違いを許容することで 修正を試みる
mod_sslExtensionStrong cryptography using the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols
mod_statusBaseサーバの活動状況と性能に関する情報を提供する
mod_substituteExtensionPerform search and replace operations on response bodies
mod_suexecExtension指定されたユーザとグループで CGI スクリプトを実行する
mod_systemdExtensionProvides better support for systemd integration
mod_tlsExperimentalTLS v1.2 and v1.3 implemented in memory-safe Rust via the rustls library
mod_unique_idExtensionそれぞれのリクエストに対する一意な識別子の入った環境変数を 提供する
mod_unixdBaseBasic (required) security for Unix-family platforms.
mod_userdirBaseユーザ専用のディレクトリを提供
mod_usertrackExtensionClickstream logging of user activity on a site
mod_versionExtensionバージョン依存の設定
mod_vhost_aliasExtensionProvides for dynamically configured mass virtual hosting
mod_watchdogBaseprovides infrastructure for other modules to periodically run tasks
mod_xml2encBaseEnhanced charset/internationalisation support for libxml2-based filter modules