ぺーぺーSEのブログ

備忘録・メモ用サイト。

Apache、TomcatのHTTPエラーページの設定

ApacheのHTTPエラーページ

httpd.confにて下記のように設定可能。

ErrorDocument 400 /error/400.html
ErrorDocument 401 /error/401.html
ErrorDocument 403 /error/403.html
ErrorDocument 404 /error/404.html
ErrorDocument 405 /error/405.html
ErrorDocument 408 /error/408.html
ErrorDocument 410 /error/410.html
ErrorDocument 411 /error/411.html
ErrorDocument 412 /error/412.html
ErrorDocument 413 /error/413.html
ErrorDocument 414 /error/414.html
ErrorDocument 415 /error/415.html
ErrorDocument 500 /error/500.html
ErrorDocument 501 /error/501.html
ErrorDocument 502 /error/502.html
ErrorDocument 503 /error/503.html
ErrorDocument 506 /error/506.html

エラーページを返却したくない場合はこの設定を行わない。

参考
http://kajuhome.com/apache_err_custom.shtml

TomcatのHTTPエラーページ

  • server.xmlでの設定
    • Host要素、errorReportValveClass属性にてデフォルトエラーページの出力を指定する。
    • デフォルトでは「org.apache.catalina.valves.ErrorReportValve」クラスとなっており、「errorReportValveClass=""」と設定することでTomcat標準のエラーページは出力されず、HTTPステータスコードだけが返される。
  • web.xmlでの設定
    • error-page要素にて設定。
<error-page>
  <error-code>404</error-code>
  <location>/error/404.html</location>
</error-page>

アプリケーション配下にある「WEB-INF\web.xml」でもTomcat全体の設定ファイル「%CATALINA_HOME%\conf\web.xml」でも設定可能。
セキュリティの観点から後者で設定する方が無難。
エラーページを返却したくない場合はこの設定を行わない。

server.xmlとweb.xmlの設定の関係性については不明。
ただ、server.xmlの設定はデフォルトでweb.xmlerror-pageの設定を行わなかった場合、エラーページが表示された。

参考:
http://gmt-24.net/archives/317
http://tomcat.apache.org/tomcat-7.0-doc/config/host.html#Standard_Implementation
http://www.atmarkit.co.jp/fjava/javatips/064container011.html
http://d.hatena.ne.jp/skirnir/20080521/1211342519
http://www.sk-jp.com/java/servlet/webxml.html#h53