httpd.confとは?
httpd.conf は、Apache HTTP Server のメイン設定ファイルです。ポート・ドキュメントルート・モジュール読込・アクセス制御・ログ出力など、Apache の動作のほぼすべてをこのファイルから制御します。
大規模な設定は1ファイルにまとめるとメンテが大変なため、httpd-vhosts.conf (バーチャルホスト) や httpd-ssl.conf (SSL/TLS)、conf.d/ などに分割して Include で読み込むのが一般的です。
設置場所の例
| OS / 配布 | 主な配置先 |
| RHEL / Rocky / Alma | /etc/httpd/conf/httpd.conf、追加分は /etc/httpd/conf.d/*.conf |
| Debian / Ubuntu | /etc/apache2/apache2.conf、/etc/apache2/sites-available/*.conf |
| Alpine | /etc/apache2/httpd.conf |
| Windows (XAMPP 等) | C:\xampp\apache\conf\httpd.conf |
主要なディレクティブ
| ディレクティブ | 役割 |
ServerRoot | Apache のインストール基準ディレクトリ |
Listen | 待ち受けポート (例: Listen 80、Listen 443) |
User / Group | Apache プロセス実行ユーザ・グループ |
ServerName | サーバ名 (ホスト) |
ServerAdmin | 管理者メールアドレス |
DocumentRoot | 公開ルートディレクトリ |
<Directory> | ディレクトリ単位の制御 (許可・否定・オプション) |
<Location> / <Files> | URL/ファイル単位の制御 |
Options | Indexes・FollowSymLinks・ExecCGI 等のディレクトリ機能 |
AllowOverride | .htaccess で上書き許可する範囲 |
Require | アクセス許可制御 (Require all granted 等) |
LoadModule | モジュール読込 (rewrite / ssl / proxy 等) |
Include / IncludeOptional | 別の設定ファイルを読込 |
ErrorLog / CustomLog | ログ出力先・書式 |
LogLevel | ログレベル (warn / info / debug) |
<VirtualHost *:80> | バーチャルホスト定義 |
最小限のバーチャルホスト例
|
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example/public
ErrorLog /var/log/httpd/example_error.log
CustomLog /var/log/httpd/example_access.log combined
<Directory /var/www/example/public>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
|
関連する設定ファイル
| ファイル | 役割 |
| httpd-vhosts.conf | バーチャルホスト (同一サーバで複数ドメイン) |
| httpd-ssl.conf | SSL/TLS 設定 (証明書・暗号スイート) |
| httpd-mpm.conf | MPM (prefork / worker / event) の動作チューニング |
| .htaccess | ディレクトリごとの上書き設定 (再起動不要だが性能低下) |
変更後の確認・反映
|
# 構文チェック (重要!本番反映前に必ず)
sudo apachectl configtest # または httpd -t
# 再起動 (graceful: 既存接続を切らずに再読込)
sudo systemctl reload httpd # RHEL系
sudo systemctl reload apache2 # Debian系
# 完全再起動 (構成が大きく変わったとき)
sudo systemctl restart httpd
|
運用上の注意
- 本番設定の変更は必ず
configtest で構文チェックしてから反映する
.htaccess での上書きはディレクトリ走査の負荷増になる。可能なら httpd.conf 側に書き、AllowOverride None
- 不要なモジュール (
LoadModule) は読み込まない (攻撃面の削減)
- サーバ情報を漏らさないため
ServerTokens Prod、ServerSignature Off
- 大規模設定では設定ファイルを Git 管理し、デプロイ前にレビュー
関連