诡异错误
浏览器访问脚本出错,本地执行没问题:
[root@Sven cgi-bin]# ./simple2.cgi
Content-type: text/plain
Hello, world!
错误详情
url访问脚本出现以下错误:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, root@localhost 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.
CGI脚本
#!/usr/bin/env python3
import cgi
form = cgi.FieldStorage()
name = form.getvalue('name', 'world')
print('Content-type: text/plain')
print('Hello, %s!' % name)
查错误日志解决:
[root@Sven cgi-bin]# cat /var/log/httpd/error_log
[Sat Aug 10 13:02:02 2013] [error] [client x.x.x.x] malformed header from script. Bad header=Hello, xwd!: simple2.cgi
怀疑到换行和Content-type的关系,于是在第一行print和第二行之间加了个print('\n'),执行就没问题了。当然把行日志到网上搜一下也有很多前人碰到。