我想在 apache2(ubuntu 14.04) 服务器上运行 python 代码。我已按照这些步骤操作并收到错误:
第1步:
配置1:我在下面创建了一个目录和文件
/var/www/cgi-bin
配置 2:我编辑了 /etc/apache2/sites-available/000-default.conf
Alias /cgi-bin /var/www/cgi-bin
<Directory "/var/www/cgi-bin">
Options Indexes FollowSymLinks ExecCGI
AddHandler cgi-script .cgi .py
Allow from all
</Directory>
<Directory /var/www/cgi-bin>
Options All
</Directory>
第2步:
我的 python 脚本是:index.py
#!/usr/bin/env python
import cgi;
import cgitb;cgitb.enable()
print "Content-Type: text/plain\n"
print "<b>Hello python</b>"
第 3 步:
当我使用 Chrome 浏览器运行时: URL : http://localhost/cgi-bin/index.py
第四步:
我在错误日志中收到此错误
malformed header from script 'index.py': Bad header: Hello Python
原文由 Sahadev 发布,翻译遵循 CC BY-SA 4.0 许可协议
你应该用
\r\n
结束你的标题,然后你必须打印出另一个\r\n
来表示身体即将到来。(换句话说,它将您的正文解释为标题,因为标题从未终止)