LoginSignup
2
1

More than 5 years have passed since last update.

久しぶりにcgiを作ったら,Internal Server Errorとなった

Posted at

久しぶりにcgiを作ったら,Internal Server Errorとなった

その解決を行った記録

コマンドラインからテストすると,cgiが動作した.
(入力した文字を単に返すcgi)

$ ruby hoge.cgi
(offline mode: enter name=value pairs on standard input)
textdata=aaa
Content-Type: text/html

start
aaa
end

これを,プログラム(ruby)から呼び出すと,「Internal Server Error」になった.

あれ?

下記の文字がタグ付きで返されてきた.

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, you@example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

最後に「server error logに詳しく書いてあるよ」とあったので,見てみたら
[error] [client ::1] malformed header from script. Bad header=start: hoge.cgi

とあった.

「malformed header from script」で調べたら,HTTP ヘッダーを加えなければいけないことを
思い出して,
print "Content-Type: text/html\n\n"
を最初のprintの前に追加して,解決です.

「Please contact the server administrator」って言われても,テスト環境だから,
それって自分なわけで,一瞬くじけそうになった.
とにかく,まずはログを見るが基本と再認識しました.

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1