ErrorDocumentについて †ErrroDocumentとは、403、404といったエラーステータスをデフォルトの表示から変更することが出来るもの。 デフォルト †# vim /etc/httpd/conf/httpd.conf 831 # Some examples: 832 #ErrorDocument 500 "The server made a boo boo." 833 #ErrorDocument 404 /missing.html 834 #ErrorDocument 404 "/cgi-bin/missing_handler.pl" 835 #ErrorDocument 402 http://www.example.com/subscription_info.html 831行目辺りにErrorDocumentの書き方が紹介されている。 870 # ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var 871 # ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var 872 # ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var 873 # ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var 874 # ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var 875 # ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var 876 # ErrorDocument 410 /error/HTTP_GONE.html.var 877 # ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var 878 # ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var 879 # ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var 880 # ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var 881 # ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var 882 # ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var 883 # ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var 884 # ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var 885 # ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var 886 # ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var
カスタマイズ †実際に作ってみたのでそれを例に説明。 # vim /etc/httpd/conf.d/sorry.conf <VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com DocumentRoot /home/sorry ServerName testtest.com ErrorLog /home/sorry/logs/error_log CustomLog /home/sorry/logs/access_log common <Directory /> Order allow,deny Allow from 192.168.1.1 </Directory> Alias /error/ "/home/403/error/" ErrorDocument 403 /error/403.html <Directory /home/403/error/> Order allow,deny Allow from all </Directory> </VirtualHost> 凄く適当に作ってあるが立派に動くので、適時読み替えること。 DocumentRoot /home/sorry †DocumentRootを必ず確認すること(これはapacheの基本)。 <Directory /> Order allow,deny Allow from 192.168.1.0/24 </Directory> 上記であれば192.168.1.0/24以外からのアクセスは403になる。 ErrorDocument 403 /error/403.html †次に順番が逆になってしまうが、ErrorDocumentの指定。 書式は
ErrorDocument [ステータスコード] (DocumentRootからの)/sorryページ Alias /error/ "/home/403/error/" †そして一番大切なのがAlias行。 <Directory /home/403/error/> Order allow,deny Allow from all </Directory> 最後にsorryページが外からアクセスできるようにディレクティブを書いてあげる。 参考 † |