#freeze
**設定 [#j97fbb36]

#contents

----
***http.conf [#j633051a]
Global的設定。
細かい設定はIncludeで読み込む。
 ServerRoot "/usr/local/apache2"
 
 Listen xxx.xxx.xxx.xxx:80
 IPアドレスバインドしたいときはIPアドレスも記述
 
 LoadModule cache_module       modules/mod_cache.so
 LoadModule disk_cache_module  modules/mod_disk_cache.so
 LoadModule mem_cache_module   modules/mod_mem_cache.so
 LoadModule deflate_module     modules/mod_deflate.so
 LoadModule logio_module       modules/mod_logio.so
 LoadModule headers_module     modules/mod_headers.so
 LoadModule php5_module        modules/libphp5.so
 LoadModule cidr_lookup_module modules/mod_cidr_lookup.so
 
 <IfModule !mpm_netware_module>
 <IfModule !mpm_winnt_module>
 User daemon
 Group daemon
 </IfModule>
 </IfModule>
 
 ServerAdmin webmaster@example.jp
 
 ServerName www.example.jp
 
 DocumentRoot "/usr/local/apache2/htdocs"
 
 <Directory />
     Options FollowSymLinks
     AllowOverride None
     Order deny,allow
     Deny from all
 </Directory>
 まずルートをアクセス禁止にする。
 
 <Directory "/usr/local/apache2/htdocs">
     Options FollowSymLinks
     AllowOverride None
     Order allow,deny
     Allow from all
 </Directory>
 その後、必要な許可を与えていく。
 
 <IfModule dir_module>
     DirectoryIndex index.html
 </IfModule>
 Globalで一旦一括指定、各ディレクトリで個別指定。
 
 <FilesMatch "^\.ht">
     Order allow,deny
     Deny from all
     Satisfy All
 </FilesMatch>
 .htで始まるファイルはアクセス禁止。
 
 ErrorLog "logs/error_log"
 LogLevel warn
 
 <IfModule log_config_module>
     LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
     LogFormat "%h %l %u %t \"%r\" %>s %b" common
 
     <IfModule logio_module>
         LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
     </IfModule>
 
     CustomLog "logs/access_log" combined
 </IfModule>
 ログフォーマットの指定。細かい出力制御も可能。
 
 
 <IfModule alias_module>
     ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"
 </IfModule>
 最近ではあんまし使わない希ガス( ´ω`)
 
 <Directory "/usr/local/apache2/cgi-bin">
     AllowOverride None
     Options None
     Order allow,deny
     Allow from all
 </Directory>
 Options NoneでもScriptAliasなのでCGI動作する。
 
 DefaultType text/plain
 
 <IfModule mime_module>
     TypesConfig conf/mime.types
     AddType application/x-compress .Z
     AddType application/x-gzip .gz .tgz
     AddType application/x-httpd-php .php
     AddHandler cgi-script .cgi
     AddType text/html .shtml
     AddOutputFilter INCLUDES .shtml
 </IfModule>
   
 Include conf/extra/httpd-mpm.conf
 Include conf/extra/httpd-userdir.conf
 Include conf/extra/httpd-vhosts.conf
 Include conf/extra/httpd-default.conf
 
 Include conf/extra/httpd-ssl.conf
 <IfModule ssl_module>
 SSLRandomSeed startup builtin
 SSLRandomSeed connect builtin
 </IfModule>

***httpd-autoindex.conf [#c7a90bf3]
ディレクトリ表示させたときの表示設定。
 IndexOptions FancyIndexing HTMLTable VersionSort
 
 Alias /icons/ "/usr/local/apache2/icons/"
 
 <Directory "/usr/local/apache2/icons">
     Options Indexes MultiViews
     AllowOverride None
     Order allow,deny
     Allow from all
 </Directory>
 
 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^^
 
 DefaultIcon /icons/unknown.gif
 
 #AddDescription "GZIP compressed document" .gz
 #AddDescription "tar archive" .tar
 #AddDescription "GZIP compressed tar archive" .tgz
 
 ReadmeName README.html
 HeaderName HEADER.html
 
 IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t

***httpd-dav.conf [#rd93b47f]
WebDAVの設定。必要モジュールはmod_davとmod_dav_fs。~
その他、Digest認証のためにmod_auth_digest、mod_authn_fileなど。~
あとから組み込むのはなんだか大変なので~
使うなら最初からsharedなりmodulesなりでコンパイルしておくとよい。~

 DavLockDB "/usr/local/apache2/var/DavLock"
 ロックファイルの指定。
 
 Alias /uploads "/usr/local/apache2/uploads"
 
 <Directory "/usr/local/apache2/uploads">
     Dav On
     Order Allow,Deny
     Allow from all
     AuthType Digest
     AuthName DAV-upload
     AuthUserFile "/usr/local/apache2/user.passwd"
     AuthDigestProvider file
     <LimitExcept GET OPTIONS>
         require user admin
     </LimitExcept>
     GETとOPTIONS以外のメソッドはadminさんしか使えないように制限。
 </Directory>
 
 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
 具合の悪いクライアントへの対応。

***httpd-default.conf [#w8a0ceb9]
基本設定。Globalに書いてもよさそうなのにね( ´ω`)
 Timeout 300
 KeepAlive On
 HTTP1.1(と1.0拡張)で有効。
 
 MaxKeepAliveRequests 100
 KeepAliveの間処理出来るリクエストの数。
 100なら100個のリクエストを処理したら接続を切る。
 0で無制限になるのだが、プロセスなりスレッドなり
 無駄が増えるので相当リッチな鯖でもそれはやめた方がいい。
 
 KeepAliveTimeout 5
 次のリクエストを待つ秒数。
 5なら5秒待ってリクエストがなかったら接続を切る。
 
 UseCanonicalName Off
 これちょっとややこしい。
 Apacheが自分の名前をServerNameディレクティブの内容を見て決めるか
 クライアントから言われた名前にしちゃうかの設定。
 
   ServerName www.example.jp:80と設定、
   イントラではhostsでdevelopと設定、
   クライアントが"http://develop/hoge"と最後のスラッシュなしで
   hogeディレクトリにアクセスしたとする。
 
   Onの場合:ServerNameを見るのでhttp://www.example.jp/hoge/に
   mod_dirがスラッシュつけてリダイレクトする。
   イントラ側で"www.example.jp"のIPアドレスが引けなければアウト。
 
   Offの場合:クライアントが言う名前を使うのでhttp://develop/hoge/に
   mod_dirがスラッシュつけてリダイレクトする。
   イントラ側ではhostsでIPアドレスが引けるのでおk。
 
   通常はOffでの運用となるでしょう( ´ω`)
   よく「最後にスラッシュつけるつけないの設定!」と
   思われているようですが違いますヨ。
   (それはDirectorySlashで、これをOffにする理由はない)
 
 AccessFileName .htaccess
 
 ServerTokens Full
 ServerSignature On
 セキュリティの為に隠しましょう!
 とか言われてましたけど、ぶっちゃけ臭いものに蓋をしてるだけ。
 隠す前に対策しましょうや( ´ω`)
 
 HostnameLookups On
 名前引くか引かないかですけど
 ウチは弱小だし引く(`・ω・´)!
 
 TraceEnable Off
 TRACEメソッド禁止。通常運用時はOffでしょう。

***httpd-info.conf [#kde039f0]
サーバのリクエスト状況やらプロセス状態やらなんやらの表示設定。
 
 <Location /server-status>
     SetHandler server-status
     Order deny,allow
     Deny from all
     Allow from .example.com
 </Location>
 
 #ExtendedStatus On
 
 <Location /server-info>
     SetHandler server-info
     Order deny,allow
     Deny from all
     Allow from .example.com
 </Location>

***httpd-language.conf [#l1037296]
コンテントネゴシエーションでの言語設定。~
クライアントの言語設定に対応した言語の~
ドキュメントを返したいときは大事。

 # DefaultLanguage nl
 
 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 tr .tr
 AddLanguage zh-CN .zh-cn
 AddLanguage zh-TW .zh-tw
 
 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 tr zh-CN zh-TW
 
 ForceLanguagePriority Prefer Fallback
 
 AddCharset us-ascii.ascii .us-ascii
 AddCharset ISO-8859-1  .iso8859-1  .latin1
 AddCharset ISO-8859-2  .iso8859-2  .latin2 .cen
 AddCharset ISO-8859-3  .iso8859-3  .latin3
 AddCharset ISO-8859-4  .iso8859-4  .latin4
 AddCharset ISO-8859-5  .iso8859-5  .cyr .iso-ru
 AddCharset ISO-8859-6  .iso8859-6  .arb .arabic
 AddCharset ISO-8859-7  .iso8859-7  .grk .greek
 AddCharset ISO-8859-8  .iso8859-8  .heb .hebrew
 AddCharset ISO-8859-9  .iso8859-9  .latin5 .trk
 AddCharset ISO-8859-10  .iso8859-10  .latin6
 AddCharset ISO-8859-13  .iso8859-13
 AddCharset ISO-8859-14  .iso8859-14  .latin8
 AddCharset ISO-8859-15  .iso8859-15  .latin9
 AddCharset ISO-8859-16  .iso8859-16  .latin10
 AddCharset ISO-2022-JP .iso2022-jp .jis
 AddCharset ISO-2022-KR .iso2022-kr .kis
 AddCharset ISO-2022-CN .iso2022-cn .cis
 AddCharset Big5.Big5   .big5 .b5
 AddCharset cn-Big5 .cn-big5
 # For russian, more than one charset is used (depends on client, mostly):
 AddCharset WINDOWS-1251 .cp-1251   .win-1251
 AddCharset CP866   .cp866
 AddCharset KOI8  .koi8
 AddCharset KOI8-E  .koi8-e
 AddCharset KOI8-r  .koi8-r .koi8-ru
 AddCharset KOI8-U  .koi8-u
 AddCharset KOI8-ru .koi8-uk .ua
 AddCharset ISO-10646-UCS-2 .ucs2
 AddCharset ISO-10646-UCS-4 .ucs4
 AddCharset UTF-7   .utf7
 AddCharset UTF-8   .utf8
 AddCharset UTF-16  .utf16
 AddCharset UTF-16BE .utf16be
 AddCharset UTF-16LE .utf16le
 AddCharset UTF-32  .utf32
 AddCharset UTF-32BE .utf32be
 AddCharset UTF-32LE .utf32le
 AddCharset euc-cn  .euc-cn
 AddCharset euc-gb  .euc-gb
 AddCharset euc-jp  .euc-jp
 AddCharset euc-kr  .euc-kr
 #Not sure how euc-tw got in - IANA doesn't list it???
 AddCharset EUC-TW  .euc-tw
 AddCharset gb2312  .gb2312 .gb
 AddCharset iso-10646-ucs-2 .ucs-2 .iso-10646-ucs-2
 AddCharset iso-10646-ucs-4 .ucs-4 .iso-10646-ucs-4
 AddCharset shift_jis   .shift_jis .sjis

***httpd-manual.conf [#la4b2fa4]
マニュアルディレクトリの設定。
通常Includeしないので省略。

***httpd-mpm.conf [#i4f73058]
プロセスやスレッドの設定。パフォーマンスチューンの一部。
とりあえずpreforkだけ。
 <IfModule !mpm_netware_module>
     PidFile "logs/httpd.pid"
 </IfModule>
 
 <IfModule !mpm_winnt_module>
 <IfModule !mpm_netware_module>
 LockFile "logs/accept.lock"
 </IfModule>
 </IfModule>
 
 <IfModule mpm_prefork_module>
     StartServers          5
     最初に起動するプロセス数。
 
     MinSpareServers       5
     MaxSpareServers      10
     スペアプロセスの制御。
     上記設定だと
     最低5個はスペアを用意して
     10個を超えたらプロセスを落とす。
 
     MaxClients          150
     最大プロセス作成数=最大接続数。
     サーバリソースとの兼ね合いだが大きいに越したことはない。
     上限自体はServerLimitで設定する。デフォは256まで。
 
     MaxRequestsPerChild   0
     1つの子プロセスで処理するリクエストの数。
     デフォは10000。
     10000回リクエストを処理すると子プロセスは落とされる。
     0で無制限になる=子プロセス落とさない。
     例えば負荷が一時的に上昇して子プロセスを大量生成してしまうと
     負荷が収まったときには無駄なプロセスばかりになってしまうので制限するとよい。
     KeepAliveが有効だと、リクエスト数自体はMaxKeepAliveRequestに左右され
     ここでは1子プロセスあたりのコネクション回数設定ということになる。
 </IfModule>
***httpd-multilang-errordoc.conf [#l744a81e]
多言語対応エラーページ設定。

 Alias /error/ "/usr/local/apache2/error/"
 
 <Directory "/usr/local/apache2/error">
     AllowOverride None
     Options IncludesNoExec
     AddOutputFilter Includes html
     AddHandler type-map var
     Order allow,deny
     Allow from all
     LanguagePriority en cs de es fr it ja ko nl pl pt-br ro sv tr
     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

***httpd-ssl.conf [#z075025a]
HTTPS設定。~
2.2系から起動時の"startssl"は無くなっており~
SSL設定が正しく設定されていれば自動的に対応する。

 #SSLRandomSeed startup file:/dev/random  512
 #SSLRandomSeed startup file:/dev/urandom 512
 #SSLRandomSeed connect file:/dev/random  512
 #SSLRandomSeed connect file:/dev/urandom 512
 
 Listen xxx.xxx.xxx.xxx:443
 
 AddType application/x-x509-ca-cert .crt .der
 AddType application/x-pkcs7-crl    .crl
 
 SSLPassPhraseDialog  builtin
 
 #SSLSessionCache         "dbm:/usr/local/apache2/logs/ssl_scache"
 SSLSessionCache        "shmcb:/usr/local/apache2/logs/ssl_scache(512000)"
 SSLSessionCacheTimeout  300
 
 SSLMutex  "file:/usr/local/apache2/logs/ssl_mutex"
 
 <VirtualHost _default_:443>
 DocumentRoot "/usr/local/apache2/htdocs"
 ServerName www.example.jp:443
 ServerAdmin webmaster@example.jp
 ErrorLog "/usr/local/apache2/logs/error_log"
 TransferLog "/usr/local/apache2/logs/access_log"
 基本VirtualHostの設定に従う。
  
 SSLEngine on
 
 SSLCipherSuite TLSv1:SHA:!MD5:!RC4:!DES:!NULL:@STRENGTH
 
 SSLCertificateFile "/usr/local/apache2/conf/server.crt"
 #SSLCertificateFile "/usr/local/apache2/conf/server-dsa.crt"
 SSLCertificateKeyFile "/usr/local/apache2/conf/server.key"
 #SSLCertificateKeyFile "/usr/local/apache2/conf/server-dsa.key"
 #SSLCertificateChainFile "/usr/local/apache2/conf/server-ca.crt"
 
 ここから
 #SSLCACertificatePath "/usr/local/apache2/conf/ssl.crt"
 #SSLCACertificateFile "/usr/local/apache2/conf/ssl.crt/ca-bundle.crt"
 #SSLCARevocationPath "/usr/local/apache2/conf/ssl.crl"
 #SSLCARevocationFile "/usr/local/apache2/conf/ssl.crl/ca-bundle.crl"
  
 #SSLVerifyClient require
 #SSLVerifyDepth  10
 
 #<Location />
 #SSLRequire (    %{SSL_CIPHER} !~ m/^(EXP|NULL)/ \
 #            and %{SSL_CLIENT_S_DN_O} eq "Snake Oil, Ltd." \
 #            and %{SSL_CLIENT_S_DN_OU} in {"Staff", "CA", "Dev"} \
 #            and %{TIME_WDAY} >= 1 and %{TIME_WDAY} <= 5 \
 #            and %{TIME_HOUR} >= 8 and %{TIME_HOUR} <= 20       ) \
 #           or %{REMOTE_ADDR} =~ m/^192\.76\.162\.[0-9]+$/
 #</Location>
 このあたりはクライアント証明書運用では大事。
 
 #SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
 <FilesMatch "\.(cgi|shtml|phtml|php)$">
     SSLOptions +StdEnvVars
 </FilesMatch>
 #<Directory "/usr/local/apache2/cgi-bin">
 #    SSLOptions +StdEnvVars
 #</Directory>
 
 BrowserMatch ".*MSIE.*" \
          nokeepalive ssl-unclean-shutdown \
          downgrade-1.0 force-response-1.0
 
 CustomLog "/usr/local/apache2/logs/ssl_request_log" \
           "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
 </VirtualHost>

***httpd-userdir.conf [#ned00a50]
ユーザディレクトリの設定。~
ウチでは使わないのでコメントアウトしてあるが~
運用時はセキュリティ面含めて正しく設定する。
 #UserDir public_html
 UserDir disabled
 
 #<Directory "/home/*/public_html">
 #    AllowOverride FileInfo AuthConfig Limit Indexes
 #    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
 #    <Limit GET POST OPTIONS>
 #        Order allow,deny
 #        Allow from all
 #    </Limit>
 #    <LimitExcept GET POST OPTIONS>
 #        Order deny,allow
 #        Deny from all
 #    </LimitExcept>
 #</Directory>

***httpd-vhosts.conf [#tb8479c2]
バーチャルホスト設定。~
ネームベースとIPアドレスベースで若干異なる。~
上から順にマッチングしていく。~
Server Name Indication対応(OpenSSL0.9.8f以降、拡張されてる場合)だと~
ネームベースでもSSL運用可能だが~
残念ながらブラウザ側対応が万全ではない。~
Includeなどで設定を読み込んでいる場合、~
各バーチャルホストごとに読み込ませる必要があるディレクティブもあるので注意。~
ウチではblogと他コンテンツでネームベース運用している。
 NameVirtualHost *:80
 
 <VirtualHost *:80>
     ServerAdmin webmaster@example.jp
     DocumentRoot "/usr/local/apache2/htdocs"
     ServerName www.example.jp
     ServerAlias www.example.jp
     ErrorLog "logs/error_log"
     CustomLog "logs/access_log" combined
 </VirtualHost>
 
 <VirtualHost *:80>
     ServerAdmin webmaster@example.jp
     DocumentRoot "/usr/local/apache2/htdocs/another"
     ServerName another.example.jp
     ErrorLog "logs/another_error_log"
     CustomLog "logs/another_access_log" combined
 </VirtualHost>

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS