久しぶりにcgiを作ったら,Internal Server Errorとなった
久しぶりに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, [email protected] 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」って言われても,テスト環境だから,
それって自分なわけで,一瞬くじけそうになった.
とにかく,まずはログを見るが基本と再認識しました.
Author And Source
この問題について(久しぶりにcgiを作ったら,Internal Server Errorとなった), 我々は、より多くの情報をここで見つけました https://qiita.com/taro373/items/3bd0bd9d5cf1639d007a著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .