LoginSignup
20
23

More than 5 years have passed since last update.

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

Posted at

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

環境

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したデフォルト設定ファイルをもとにしています。
すべての設定を確認している訳ではありません。

設定ファイルの中身

43.IndexIgnore
ディレクトリの一覧を行う際に無視すべきファイルリストに追加する。
(IndexIgnore file [file] ...)

httpd.conf
#
# IndexIgnore is a set of filenames which directory indexing should ignore
# and not include in the listing.  Shell-style wildcarding is permitted.
#
IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t

44.DefaultLanguage / AddLanguage
DefaultLanguage:
Apache がディレクティブのスコープ(例えば、その時点の の範囲)にある、
明示的な言語拡張子 (AddLanguage で設定される .fr や .de) のない全てのファイルを、
指定された MIME-lang 言語であるとみなすようにする。
(DefaultLanguage MIME-lang)

注意1: DefaultLanguageは一つの言語しか指定できない。
注意2: DefaultLanguageが有効でなく、ファイルにAddLanguageで設定された
言語の拡張子がないときは、ファイルには言語属性がないとみなされる。

AddLanguage:
与えられた拡張子を指定された content language にマップする。
(AddLanguage MIME-lang extension [extension] ...)

httpd.conf
#
# DefaultLanguage and AddLanguage allows you to specify the language of 
# a document. You can then use content negotiation to give a browser a 
# file in a language the user can understand.
#
# Specify a default language. This means that all data
# going out without a specific language tag (see below) will 
# be marked with this one. You probably do NOT want to set
# this unless you are sure it is correct for all cases.
#
# * It is generally better to not mark a page as 
# * being a certain language than marking it with the wrong
# * language!
#
# DefaultLanguage nl
#
# Note 1: The suffix does not have to be the same as the language
# keyword --- those with documents in Polish (whose net-standard
# language code is pl) may wish to use "AddLanguage pl .po" to
# avoid the ambiguity with the common suffix for perl scripts.
#
# Note 2: The example entries below illustrate that in some cases 
# the two character 'Language' abbreviation is not identical to 
# the two character 'Country' code for its country,
# E.g. 'Danmark/dk' versus 'Danish/da'.
#
# Note 3: In the case of 'ltz' we violate the RFC by using a three char
# specifier. There is 'work in progress' to fix this and get
# the reference data for rfc1766 cleaned up.
#
# Catalan (ca) - Croatian (hr) - Czech (cs) - Danish (da) - Dutch (nl)
# English (en) - Esperanto (eo) - Estonian (et) - French (fr) - German (de)
# Greek-Modern (el) - Hebrew (he) - Italian (it) - Japanese (ja)
# Korean (ko) - Luxembourgeois* (ltz) - Norwegian Nynorsk (nn)
# Norwegian (no) - Polish (pl) - Portugese (pt)
# Brazilian Portuguese (pt-BR) - Russian (ru) - Swedish (sv)
# Simplified Chinese (zh-CN) - Spanish (es) - Traditional Chinese (zh-TW)
#
AddLanguage ca .ca
AddLanguage cs .cz .cs
AddLanguage da .dk
AddLanguage de .de
AddLanguage el .el
AddLanguage en .en
AddLanguage eo .eo
AddLanguage es .es
AddLanguage et .et
AddLanguage fr .fr
AddLanguage he .he
AddLanguage hr .hr
AddLanguage it .it
AddLanguage ja .ja
AddLanguage ko .ko
AddLanguage ltz .ltz
AddLanguage nl .nl
AddLanguage nn .nn
AddLanguage no .no
AddLanguage pl .po
AddLanguage pt .pt
AddLanguage pt-BR .pt-br
AddLanguage ru .ru
AddLanguage sv .sv
AddLanguage zh-CN .zh-cn
AddLanguage zh-TW .zh-tw

45.LanguagePriority
MultiViews リクエストを扱うときに、
クライアントが優先順位を提供していない場合の言語の優先順位を設定する。
(LanguagePriority MIME-lang [MIME-lang] ...)

LanguagePriority en fr de
# foo.html がリクエストされ、foo.html.fr と foo.html.de が両方存在し、
# ブラウザが言語の優先順位を提供してない場合は foo.html.fr が返される。
httpd.conf
#
# LanguagePriority allows you to give precedence to some languages
# in case of a tie during content negotiation.
#
# Just list the languages in decreasing order of preference. We have
# more or less alphabetized them here. You probably want to change this.
#
LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW

46.ForceLanguagePriority
要求に合うドキュメントを一つだけ返すことができないときに、
LanguagePriorityを使ってネゴシエーションの結果を返す。
(ForceLanguagePriority None|Prefer|Fallback [Prefer|Fallback])

構文 内容
ForceLanguagePriority None 何も返さない。
ForceLanguagePriority Prefer 同等の選択肢がいくつかあるときに、
HTTPの 300 (MULTIPLE CHOICES) を返す代わりに、
LanguagePriorityを使って一つだけドキュメントを返すようにする。
ForceLanguagePriority Fallback HTTP 406 (NOT ACCEPTABLE) を送信する代わりに、
LanguagePriorityが正しい結果を送る。
ForceLanguagePriority Prefer Fallback 複数のデータ型(variant)がある場合、LanguagePriorityの最初の
データ型が送られ、クライアントの許容言語に合うデータ型がないときは
存在するドキュメントで最初のものが送られる。
httpd.conf
#
# ForceLanguagePriority allows you to serve a result page rather than
# MULTIPLE CHOICES (Prefer) [in case of a tie] or NOT ACCEPTABLE (Fallback)
# [in case no accepted languages matched the available variants]
#
ForceLanguagePriority Prefer Fallback

47.AddDefaultCharset
(レスポンスのコンテントタイプが text/plain あるいは text/html の場合に限り)
レスポンスに追加するメディアタイプの文字セットパラメータのデフォルト値を指定する。
(AddDefaultCharset On|Off|charset)

注意: レスポンスのHTML内で META 要素で指定された、どのような文字セットも無効にするが、
最終的な挙動はユーザのクライアント側の設定で決まる。

構文 内容
AddDefaultCharset On Apache 内部のデフォルト文字セット iso-8859-1 に設定される。
AddDefaultCharset Off この機能を無効にする。
AddDefaultCharset charset その他 charset に指定できる値であれば、どんな値でも使える。
httpd.conf
#
# Specify a default charset for all content served; this enables
# interpretation of all content as UTF-8 by default.  To use the 
# default browser choice (ISO-8859-1), or to allow the META tags
# in HTML content to override this choice, comment out this
# directive:
#
AddDefaultCharset UTF-8

48.AddType / AddEncoding /AddHandler / AddOutputFilter
AddType:
与えられた拡張子を指定されたコンテントタイプにマップする。
(AddType MIME-type extension [extension] ...)

AddEncoding:
与えられた拡張子を指定されたエンコーディングにマップする。
(AddEncoding MIME-enc extension [extension] ...)

AddHandler:
ファイル名の拡張子を指定されたハンドラにマップする。
(AddHandler handler-name extension [extension] ...)

AddOutputFilter:
ファイル名の拡張子をサーバからの応答を処理するフィルタにマップする。
(AddOutputFilter filter[;filter...] extension [extension] ...)

httpd.conf
#
# AddType allows you to add to or override the MIME configuration
# file mime.types for specific file types.
#
#AddType application/x-tar .tgz

#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
# Despite the name similarity, the following Add* directives have nothing
# to do with the FancyIndexing customization directives above.
#
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz

# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz

#
#   MIME-types for downloading Certificates and CRLs
#
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl    .crl

#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
#AddHandler cgi-script .cgi

#
# For files that include their own HTTP headers:
#
#AddHandler send-as-is asis

#
# For type maps (negotiated resources):
# (This is enabled by default to allow the Apache "It Worked" page
#  to be distributed in multiple languages.)
#
AddHandler type-map var

#
# Filters allow you to process content before it is sent to the client.
#
# To parse .shtml files for server-side includes (SSI):
# (You will also need to add "Includes" to the "Options" directive.)
#
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

49.ErrorDocument
エラーが発生したときにサーバがクライアントに送る内容を設定する。
(ErrorDocument error-code document)

httpd.conf
#
# Action lets you define media types that will execute a script whenever
# a matching file is called. This eliminates the need for repeated URL
# pathnames for oft-used CGI file processors.
# Format: Action media/type /cgi-script/location
# Format: Action handler-name /cgi-script/location
#

#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
#

#
# Putting this all together, we can internationalize error responses.
#
# We use Alias to redirect any /error/HTTP_<error>.html.var response to
# our collection of by-error message multi-language collections.  We use 
# includes to substitute the appropriate text.
#
# You can modify the messages' appearance without changing any of the
# default HTTP_<error>.html.var files by adding the line:
#
#   Alias /error/include/ "/your/include/path/"
#
# which allows you to create your own set of files by starting with the
# /var/www/error/include/ files and
# copying them to /your/include/path/, even on a per-VirtualHost basis.
#

Alias /error/ "/var/www/error/"

<IfModule mod_negotiation.c>
<IfModule mod_include.c>
    <Directory "/var/www/error">
        AllowOverride None
        Options IncludesNoExec
        AddOutputFilter Includes html
        AddHandler type-map var
        Order allow,deny
        Allow from all
        LanguagePriority en es de fr
        ForceLanguagePriority Prefer Fallback
    </Directory>

#    ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var
#    ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var
#    ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var
#    ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var
#    ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var
#    ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var
#    ErrorDocument 410 /error/HTTP_GONE.html.var
#    ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var
#    ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var
#    ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var
#    ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var
#    ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var
#    ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var
#    ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var
#    ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var
#    ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var
#    ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var

</IfModule>
</IfModule>

50.BrowserMatch
HTTP User-Agent に基づいて環境変数を設定する。
(BrowserMatch regex [!]env-variable[=value] [[!]env-variable[=value]] ...)

httpd.conf
#
# The following directives modify normal HTTP response behavior to
# handle known problems with browser implementations.
#
BrowserMatch "Mozilla/2" nokeepalive
BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0
BrowserMatch "RealPlayer 4\.0" force-response-1.0
BrowserMatch "Java/1\.0" force-response-1.0
BrowserMatch "JDK/1\.0" force-response-1.0

#
# The following directive disables redirects on non-GET requests for
# a directory that does not include the trailing slash.  This fixes a 
# problem with Microsoft WebFolders which does not appropriately handle 
# redirects for folders with DAV methods.
# Same deal with Apple's DAV filesystem and Gnome VFS support for DAV.
#
BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully
BrowserMatch "MS FrontPage" redirect-carefully
BrowserMatch "^WebDrive" redirect-carefully
BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully
BrowserMatch "^gnome-vfs/1.0" redirect-carefully
BrowserMatch "^XML Spy" redirect-carefully
BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully

51.<Location> / SetHandler
<Location>:
URL により中に書かれたディレクティブの適用範囲を制限する。
優先順位として、
1.<Directory> セクションと .htaccess の読み込み
2.<Files> セクションを 適用
3.設定ファイルに現れた順に処理される。

SetHandler:
マッチするファイルがハンドラで処理されるようにする。(SetHandler handler-name|None)
なお、None という値を設定することで、前の方の SetHandler で定義された設定を無効にする。

httpd.conf
#
# Allow server status reports generated by mod_status,
# with the URL of http://servername/server-status
# Change the ".example.com" to match your domain to enable.
#
#<Location /server-status>
#    SetHandler server-status
#    Order deny,allow
#    Deny from all
#    Allow from .example.com
#</Location>

#
# Allow remote server configuration reports, with the URL of
#  http://servername/server-info (requires that mod_info.c be loaded).
# Change the ".example.com" to match your domain to enable.
#
#<Location /server-info>
#    SetHandler server-info
#    Order deny,allow
#    Deny from all
#    Allow from .example.com
#</Location>

52.<Proxy> / ProxyVia / CacheEnable / CacheRoot
<Proxy>:
マッチするプロキシされるコンテンツにのみ適用される。(<Proxy wildcard-url> ...</Proxy>)

ProxyVia:
プロキシの Via: HTTP ヘッダの使用を制御する。(ProxyVia On|Off|Full|Block)

構文 内容
ProxyVia On 各リクエストとリプライに Via: 行が追加される。
ProxyVia Off 特別な処理は行なわれない。
ProxyVia Full Via: ヘッダはコメント部分にApacheサーバのバージョンも含むようになる。
ProxyVia Block すべてのプロキシリクエストから Via: ヘッダが取り除かれる。

CacheEnable:
mod_cache モジュールがurl-string以下のURLをキャッシュするようにする。
(CacheEnable cache_type url-string)

CacheRoot:
キャッシュファイルを保管するためのディスク上のディレクトリを指定する。(CacheRoot directory)

httpd.conf
#
# Proxy Server directives. Uncomment the following lines to
# enable the proxy server:
#
#<IfModule mod_proxy.c>
#ProxyRequests On
#
#<Proxy *>
#    Order deny,allow
#    Deny from all
#    Allow from .example.com
#</Proxy>

#
# Enable/disable the handling of HTTP/1.1 "Via:" headers.
# ("Full" adds the server version; "Block" removes all outgoing Via: headers)
# Set to one of: Off | On | Full | Block
#
#ProxyVia On

#
# To enable a cache of proxied content, uncomment the following lines.
# See http://httpd.apache.org/docs/2.2/mod/mod_cache.html for more details.
#
#<IfModule mod_disk_cache.c>
#   CacheEnable disk /
#   CacheRoot "/var/cache/mod_proxy"
#</IfModule>
#

#</IfModule>
# End of proxy directives.

53.NameVirtualHost / <VirtualHost>
NameVirtualHost:
名前ベースのバーチャルホストのためのIPアドレスを指定する。(NameVirtualHost addr[:port])

<VirtualHost>:
特定のバーチャルホストに対してのみ適用されるディレクティブ群を括るために使用される。
(<VirtualHost addr[:port] [addr[:port]] ...> ... </VirtualHost>)

addrは以下が利用できる。

  • バーチャルホストの IP アドレス
  • バーチャルホストの IP に対応する完全なドメイン名(非推奨)
  • NameVirtualHost * と共に使われる、すべてのIPアドレスにマッチする文字 *
  • IPベースのバーチャルホストで他のものにマッチしないIPアドレス のための文字列 _default_
httpd.conf
### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier 
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>

以上です。

20
23
0

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
20
23