coLinux日記

coLinuxはフリーソフトを種として、よろずのシステムとぞなれりける。

Apache httpd あれこれ

2007-01-13 22:37:29 | Apache httpd
前回うまく動作した、hello.rbx をわざと hello.rb(もちろんシェルで実行しても動かないです。)にコピーして参照すると、エラーになるはずです。試してみます。
$ lynx -dump http://www.example.co.jp/cgi-bin/hello.rb
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>>00 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
....................
</body></html>

$

です。一応うまくエラーになっていますが、html が正しく認識されていません。httpd の設定がどこか間違っているからでしょうか。lynx でチェックしてみます。
$ lynx -dump -head http://www.example.co.jp/cgi-bin/hello.rb
HTTP/1.1 500 Internal Server Error
Date: Tue, xx Jan 2007 12:40:11 GMT
Server: Apache/2.2.3 (Unix) mod_ssl/2.2.3 OpenSSL/0.9.8a PHP/5.2.0 mod_ruby/1.2
.6 Ruby/1.8.5(200x-xx-xx)
Connection: close
Content-Type: text/plain
Content-Language: ja

$

Content-Type: text/plain になっています。存在しないファイルのアクセスのエラーのときは、
$ lynx -dump -head http://www.example.co.jp/cgi-bin/hello
HTTP/1.1 404 Not Found
Date: Tue, xx Jan 2007 12:44:55 GMT
Server: Apache/2.2.3 (Unix) mod_ssl/2.2.3 OpenSSL/0.9.8a PHP/5.2.0 mod_ruby/1.2
.6 Ruby/1.8.5(200x-xx-xx)
Connection: close
Content-Type: text/html; charset=iso-8859-1

$

のようになっていますので、500 の時におかしくなっています。conf ファイルでこれを制御する部分? はデフォルトですので、この出力結果はモジュールで内部生成されているようです。ソース内の modules ディレクトリ内を調べたところ、modules/http/http_protocol.c 内の get_canned_error_string で</h1> 以下を生成しているようです。これは、ap_send_error_response で呼び出していますが、このときに、ap_set_content_type が呼び出されていないのがこうなる理由みたいです。500 は、httpd.conf で ErrorDocument を指定して回避するとして、別の HTML ファイルで置き換えても、Content-type は変更できないみたいなので、
ErrorDocument 500 "500 Internal Server Error"

のような指定でしょうか。

もう1つ気がついたのは、設定では、localhost からのアクセスをロックしてあるのですが、
# lynx -dump http://localhost/cgi-bin/hello.rbx
                                   Forbidden

   You don't have permission to access /cgi-bin/hello.rbx on this server.

# tail -1 /usr/local/httpd/logs/error_log
[Mon Jan xx xx:xx:xx 2007] [error] [client 127.0.0.1] client denied by
                       server configuration: /home/data/cgi-bin/hello.rbx
# lynx -dump http://www.example.co.jp/cgi-bin/hello.rbx
Hello, World.

# tail -1 /usr/local/httpd/logs/access_log
192.168.1.100 - - [xx/Jan/2007:xx:xx:xx +0900] "GET /cgi-bin/hello.rbx HTTP/1.0" 200 13
#

つまり、lynx は、http://localhost で参照すると、127.0.0.1 としてhttpd に接続し、http://www.example.co.jp で参照すると、192.168.1.100 として接続するのですね。いつも、127.0.0.1 で接続しているのかと思ってました。ということは、2006-12-26の記述は誤りで訂正しておきます。別のケースを勘違いしたみたいです。

今回は、どうでもいいことを書き、また間違いも見つけてしまいましたが、coLinux の場合、完全な実験環境としてどんどんいじれるので気楽でいいです。Apache httpd も 2.2.4 がリリースされたのでそちらも試してみたいです。

コメント    この記事についてブログを書く
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする
« ruby mod_rubyとeruby | トップ | apache httpd 2.2.4 インスト... »
最新の画像もっと見る

コメントを投稿

Apache httpd」カテゴリの最新記事