LoginSignup
37

More than 5 years have passed since last update.

メモ:Apacheの設定ファイル(http.conf)を確認する (2)

Posted at

メモ:Apacheの設定ファイル(http.conf)を確認する (1)のつづき。

環境

Mac OS Xに仮想環境で立ち上げた
chef/centos-6.5 | CentOS 6.5 | httpd 2.2.15-30

上記環境の/etc/httpd/conf/httpd.confについて、
Apache HTTP Server Version 2.2 Documentationを見ながら確認し、項目ごとに記載していきます。

※ chef/centos-6.5のBoxにて、yum install httpdしたデフォルト設定ファイルをもとにしています。
すべての設定を確認している訳ではありません。

設定ファイルの中身

27.HostnameLookups
クライアントのIPアドレスのDNSルックアップを設定する。(HostnameLookups On|Off|Double)

構文 内容
HostnameLookups On ホスト名をログ収集できるようにDNSルックアップを有効にする。
HostnameLookups Off DNSルックアップを無効にする。
HostnameLookups Double 逆引きの後に、その結果に対して正引きを行う。

注意1: mod_authz_host でホスト名によるアクセス制御を行う場合には、設定の如何によらず2重の逆引きが実行される。
注意2: ネットワークトラフィックが増大する。

httpd.conf
#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

27.EnableMMAP
配送中にファイルを読み込むためにメモリマッピングを使うかどうか設定する。(EnableMMAP On|Off)

httpd.conf
#
# EnableMMAP: Control whether memory-mapping is used to deliver
# files (assuming that the underlying OS supports it).
# The default is on; turn this off if you serve from NFS-mounted 
# filesystems.  On some systems, turning it off (regardless of
# filesystem) can improve performance; for details, please see
# http://httpd.apache.org/docs/2.2/mod/core.html#enablemmap
#
#EnableMMAP off

28.EnableSendfile
クライアントにファイルの内容を送るときに、httpdがカーネルのsendfileサポートを使うかどうかを制御する。
(EnableSendfile On|Off)

httpd.conf
#
# EnableSendfile: Control whether the sendfile kernel support is 
# used to deliver files (assuming that the OS supports it). 
# The default is on; turn this off if you serve from NFS-mounted 
# filesystems.  Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#enablesendfile
#
#EnableSendfile off

29.ErrorLog
サーバがエラーをログ収集する場所を設定する。(ErrorLog file-path|syslog[:facility])

# file-path がパイプ (|) から始まる場合は、
# エラーログを処理するために実行されるコマンドが指定されていると解釈する。
ErrorLog "|/usr/local/bin/httpd_errors"

# ファイル名の変わりにsyslogと指定することによって、
# システムがサポートしていればsyslogd(8)を利用したロギングが有効になる。
ErrorLog syslog:user
httpd.conf
#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog logs/error_log

30.LogLevel
エラーログへ記録するメッセージの冗長性を調整する。(LogLevel level)
特定のレベルが指定された場合、それより高いレベルの全てのメッセージが報告される。

レベル 説明
emerg 緊急 - システムが利用できない Child cannot open lock file. Exiting
(子プロセスがロックファイルを開けないため終了した)
alert 直ちに対処が必要 getpwuid: couldn't determine user name from uid
(getpwuid: UID からユーザ名を特定できなかった)
crit 致命的な状態 socket: Failed to get a socket, exiting child
(socket: ソケットが得られないため、子プロセスを終了させた)
error エラー Premature end of script headers
(スクリプトのヘッダが足りないままで終わった)
warn 警告 child process 1234 did not exit, sending another SIGHUP
(子プロセス 1234 が終了しなかった。もう一度 SIGHUP を送る)
notice 普通だが、重要な情報 httpd: caught SIGBUS, attempting to dump core in ...
(httpd: SIGBUS シグナルを受け、... へコアダンプをした)
info 追加情報 "Server seems busy, (you may need to increase StartServers, or Min/MaxSpareServers)..."
(「サーバは負荷が高い、 (StartServers や Min/MaxSpareServers の値を増やす必要があるかも)」)
debug デバッグメッセージ "Opening config file ..."(設定ファイルを開いている...)
httpd.conf
#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

31.LogFormat
ログファイルで使用する書式を設定する。(LogFormat format|nickname [nickname])
(カスタムログ書式はこちら)

httpd.conf
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# "combinedio" includes actual counts of actual bytes received (%I) and sent (%O); this
# requires the mod_logio module to be loaded.
#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio

32.CustomLog
ログファイルの名前と書式を設定する。
(CustomLog file|pipe format|nickname [env=[!]environment-variable])

引数 構文 内容
第一引数 file ServerRoot からの相対パスで表されるファイル名。
第一引数 pipe パイプ文字"(※1)"と、その後に標準入力からログの情報を受けとるプログラムへのパスが続いたもの。
第二引数 format (31.LogFormatで記載した)format。
第二引数 nickname (31.LogFormatで名付けた)nickname。
第三引数 [env=[!]environment-variable] 指定された環境変数がリクエストに対して設定されていた場合、
リクエストがログ収集される(省略可能)。

※1: | Markdownの表の区切りと認識された為、こちらで記載。

httpd.conf
#
# The location and format of the access logfile (Common Logfile Format).
# If you do not define any access logfiles within a <VirtualHost>
# container, they will be logged here.  Contrariwise, if you *do*
# define per-<VirtualHost> access logfiles, transactions will be
# logged therein and *not* in this file.
#
#CustomLog logs/access_log common

#
# If you would like to have separate agent and referer logfiles, uncomment
# the following directives.
#
#CustomLog logs/referer_log referer
#CustomLog logs/agent_log agent

#
# For a single logfile with access, agent, and referer information
# (Combined Logfile Format), use the following directive:
#
CustomLog logs/access_log combined

33.ServerSignature
サーバが生成するドキュメントの最下行に付与するフッタの設定をする。(ServerSignature On|Off|EMail)
そのようなフッタ行を有効にしたい理由には、プロキシが複数連なっている場合に、ユーザはどのサーバが返したエラーメッセージかを知る手段がほとんど無い時に利用される。

構文 内容
ServerSignature On 単にドキュメントの中に、サーバのバージョン、
稼動中のバーチャルホストのServerNameの書かれた行を追加する。
ServerSignature Off フッタ行が抑制される。
ServerSignature EMail Onの情報に加え、参照されたドキュメントに対する
ServerAdminを指す"mailto:"が追加される。
httpd.conf
#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to "EMail" to also include a mailto: link to the ServerAdmin.
# Set to one of:  On | Off | EMail
#
ServerSignature On

34.Alias
ドキュメントをローカルファイルシステムのDocumentRoot以外の場所に補完する。
(Alias URL-path file-path|directory-path)

Alias /image /ftp/pub/image
# http://myserver/image/foo.gif へのリクエストに対して、
# サーバはファイル /ftp/pub/image/foo.gif を返す。

Alias /icons/ /usr/local/apache/icons/
# 上記の場合、/icons というURLはエイリアスされない。
httpd.conf
#
# Aliases: Add here as many aliases as you need (with no limit). The format is 
# Alias fakename realname
#
# Note that if you include a trailing / on fakename then the server will
# require it to be present in the URL.  So "/icons" isn't aliased in this
# example, only "/icons/".  If the fakename is slash-terminated, then the 
# realname must also be slash terminated, and if the fakename omits the 
# trailing slash, the realname must also omit it.
#
# We include the /icons/ alias for FancyIndexed directory listings.  If you
# do not use FancyIndexing, you may comment this out.
#
Alias /icons/ "/var/www/icons/"

<Directory "/var/www/icons">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

35.DAVLockDB
DAV ロックデータベースの位置を設定する。(DavLockDB file-path)

httpd.conf
#
# WebDAV module configuration section.
# 
<IfModule mod_dav_fs.c>
    # Location of the WebDAV lock database.
    DAVLockDB /var/lib/dav/lockdb
</IfModule>

36.ScriptAlias
対象ディレクトリに mod_cgi の cgi-script ハンドラで処理される CGI スクリプトがあることを示す
以外は Alias ディレクティブと同じ振る舞いを行う。

httpd.conf
#
# ScriptAlias: This controls which directories contain server scripts.
# ScriptAliases are essentially the same as Aliases, except that
# documents in the realname directory are treated as applications and
# run by the server when requested rather than as documents sent to the client.
# The same rules about trailing "/" apply to ScriptAlias directives as to
# Alias.
#
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

#
# "/var/www/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Order allow,deny
    Allow from all
</Directory>

37.Redirect
クライアントが違うURLを取得するように外部へのリダイレクトを送る。
(Redirect [status] URL-path URL)

status 内容
permanent
301
永久にリダイレクトをするステータスを返す。
temp
302
一時的なリダイレクトステータスを返す。(デフォルト)
seeother
303
"See Other"(リソースが他のもので置き換えられた)ステータスを返す。
gone
410
"Gone"(リソースが永久に削除された)ステータスを返す。
httpd.conf
#
# Redirect allows you to tell clients about documents which used to exist in
# your server's namespace, but do not anymore. This allows you to tell the
# clients where to look for the relocated document.
# Example:
# Redirect permanent /foo http://www.example.com/bar

38.IndexOptions
ディレクトリインデックスの挙動を指定する。(IndexOptions [+|-]option [[+|-]option] ...)

Option 内容
Charset=character-set 生成されたページの文字コードを指定する。
Type=MIME content-type 生成されたページのMIMEコンテンツタイプを指定できる。
DescriptionWidth 説明コラムの幅を文字数で指定することができる。
-DescriptionWidth(または非設定): mod_autoindex が最適な幅を計算するようにできる。
DescriptionWidth=n: コラム幅を n バイトに固定する。
DescriptionWidth=*: 最長の説明に合わせて必要な長さまでコラムを延ばす。
FancyIndexing 飾り付きインデックスをオンにする。
FoldersFirst サブディレクトリの一覧は必ず最初に現われて、そのディレクトリの通常のファイルはその後に続く。
(FancyIndexingも有効になっているときのみ動作。)
HTMLTable
(実験的内容)
FancyIndexingとともに指定することで、
飾りの付いたディレクトリ一覧のためにテーブルを使った単純な表を作る。
IconsAreLinks FancyIndexingにおいて、アイコンもファイル名へのリンクの一部にする。
IconHeight[=pixels] ファイルアイコンのためのimgタグにheightとwidth属性を取り込むようになる。
IconWidthと併用。
IconWidth[=pixels] ファイルアイコンのためのimgタグにheightとwidth属性を取り込むようになる。
IconHeightと併用。
IgnoreCase ファイル名は大文字小文字を区別せずにソートされる。
IgnoreClient mod_autoindex は、クライアントからの全てのクエリー変数を無視するようになる。
NameWidth ファイル名コラムの幅をバイト数で指定できる。
-NameWidth(または非設定): mod_autoindex が最適な幅を計算するようにできる。
NameWidth=n: コラム幅を n バイトに固定する。
NameWidth=*: 必要な長さまでコラムを延ばす。
ScanHTMLTitles FancyIndexingのために、HTMLドキュメントからタイトルを取り出すことを可能にする。
ShowForbidden 指定した場合であっても、サブリクエストの結果が
HTTP_UNAUTHORIZED や HTTP_FORBIDDENのファイルは
通常通り隠された状態のまま、ファイル一覧が生成される。
SuppressColumnSorting もし指定されていれば、Apache は
FancyIndexingで表示されているディレクトリ一覧での
コラムの先頭を、ソートのためのリンクにしなくなる。
SuppressDescription FancyIndexingにおけるファイルの説明を消去する。
SuppressHTMLPreamble モジュールがヘッダーファイルの中身から表示を始める。
(通常、HeaderNameで指定したファイルをディレクトリが
実際に含んでいれば、標準的なHTMLプリアンブル(, , 等)の後に、
モジュールはファイルの中身をインクルードする。
ヘッダーファイルが存在しない場合は、プリアンブルは通常通り生成される。
SuppressIcon FancyIndexingの一覧からアイコンを消去する。
SuppressLastModified FancyIndexing一覧において最終更新日時の表示を消去する。
SuppressRules ディレクトリ一覧において水平区切り線(hr タグ)を消去する。
SuppressSize FancyIndexing一覧においてファイルサイズの表示を消去する。
TrackModified HTTPヘッダ中に、リストされたディレクトリの最終更新日や ETag 値を含める。
但し、既に存在するファイルのサイズや日付のスタンプが変化しても、
全ての Unix プラットホームでは、最終更新日ヘッダーを更新しない。
VersionSort バージョン番号を含んだファイルが自然な方法でソートされるようになる。
XHTML mod_autoindexは HTML 3.2 の代わりに XHTML 1.0 のコードを出力するようになる。
httpd.conf
#
# Directives controlling the display of server-generated directory listings.
#

#
# IndexOptions: Controls the appearance of server-generated directory
# listings.
#
IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8

39.AddIconByEncoding / AddIconByType / AddIcon
AddIconByEncoding:
FancyIndexingにおいて、ファイルの隣に表示するアイコンを設定する。
(AddIconByEncoding icon MIME-encoding [MIME-encoding] ...)

AddIconByType:
FancyIndexingにおいて、ファイルの隣に表示するアイコンを設定する。
(AddIconByType icon MIME-type [MIME-type] ...)

AddIcon:
FancyIndexingにおいて、nameで終わるファイルの隣に表示するアイコンを設定する。
(AddIcon icon name [name] ...)

httpd.conf
#
# AddIcon* directives tell the server which icon to show for different
# files or filename extensions.  These are only displayed for
# FancyIndexed directories.
#
AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip

AddIconByType (TXT,/icons/text.gif) text/*
AddIconByType (IMG,/icons/image2.gif) image/*
AddIconByType (SND,/icons/sound2.gif) audio/*
AddIconByType (VID,/icons/movie.gif) video/*

AddIcon /icons/binary.gif .bin .exe
AddIcon /icons/binhex.gif .hqx
AddIcon /icons/tar.gif .tar
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip
AddIcon /icons/a.gif .ps .ai .eps
AddIcon /icons/layout.gif .html .shtml .htm .pdf
AddIcon /icons/text.gif .txt
AddIcon /icons/c.gif .c
AddIcon /icons/p.gif .pl .py
AddIcon /icons/f.gif .for
AddIcon /icons/dvi.gif .dvi
AddIcon /icons/uuencoded.gif .uu
AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl
AddIcon /icons/tex.gif .tex
AddIcon /icons/bomb.gif core

AddIcon /icons/back.gif ..
AddIcon /icons/hand.right.gif README
AddIcon /icons/folder.gif ^^DIRECTORY^^
AddIcon /icons/blank.gif ^^BLANKICON^^

40.DefaultIcon
FancyIndexingにおいて、特定のアイコンがない場合にファイルに表示するアイコンを設定する。
(DefaultIcon url-path)

httpd.conf
#
# DefaultIcon is which icon to show for files which do not have an icon
# explicitly set.
#
DefaultIcon /icons/unknown.gif

41.AddDescription
FancyIndexingにおいて、ファイルに対して表示する説明を設定する。
(AddDescription string file [file] ...)

httpd.conf
#
# AddDescription allows you to place a short description after a file in
# server-generated indexes.  These are only displayed for FancyIndexed
# directories.
# Format: AddDescription "description" filename
#
#AddDescription "GZIP compressed document" .gz
#AddDescription "tar archive" .tar
#AddDescription "GZIP compressed tar archive" .tgz

42.ReadmeName / HeaderName
ReadmeName:
インデックスの終わりに付け加えられるファイルの名前を設定する。(ReadmeName filename)

HeaderName:
インデックス一覧の先頭に挿入するファイルの名前を設定する。(HeaderName filename)

httpd.conf
#
# ReadmeName is the name of the README file the server will look for by
# default, and append to directory listings.
#
# HeaderName is the name of a file which should be prepended to
# directory indexes. 
ReadmeName README.html
HeaderName HEADER.html

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
37