スポンサーリンク

rubyでcgiがうまくいかない

phpは簡単に動くのに、10年前にperlでcgiを動かそうとしていたときみたいに、rubyで書いたcgiがServer Errorになって動かない。

http://xiaoxia.exblog.jp/1078664/
2004年 09月 24日
apache の「Premature end of script headers」

● test.cgi

—–

#!/usr/bin/ruby
print "Content-Type: text/htmlnn"
print "test"

—-

(1)改行コードをLF

(2)文字コードセットをUTF-8

(3)ファイル名の拡張子は.cgi

(4)ファイルのパーミッションは755 (サーバーの設定によるであろうが。)

(5)Content-Type: text/htmlnn なんて、perlやphpでは聞いたことなかった。なんのおまじないかさっぱり。。。

なんだか30分くらいかかったが、なんとか実行することができた。

———–

#!/usr/bin/ruby
print "Content-Type: text/htmlnn"
print("<html><head><title>Hello</title></head><body><em>Hello World</em></body></html>")

———–

これもいけた。

print("<html><head><title>Hello</title></head><body><h1 style="color:blue;">Hello World</h1></body></html>")

はServer Errorになった。<h1 style="color:blue;"> の部分がいけないのだとは思うが、理由はわからん。

スポンサーリンク