【发布时间】:2020-12-19 09:19:34
【问题描述】:
我一直在尝试使用 CGI 运行一个简单的 python 脚本hello.py,但出现 500 内部服务器错误。
我的python代码。
#!/usr/bin/python2.7
print '<html>'
print '<head>'
print '<title>Hello World - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello World! This is my first CGI program</h2>'
print '</body>'
print '</html>'
我运行python脚本的目录在/var/www/crunchworld。我启用的conf文件在`/etc/apache2/conf-available/crunchworld.conf
conf文件的样子
<Directory /var/www/crunchworld>
Options +ExecCGI
AddHandler cgi-script .cgi
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
我启用了 cgi 并为文件 hello.py 授予了必要的权限,但它仍然显示内部服务器错误。当我检查日志时,我看到了
头文件前的脚本输出结束:hello.py
我已经研究了错误并为该文件提供了适当的权限,但它不起作用。
任何帮助将不胜感激。提前致谢。
我做了进一步的改变。
- 我在 crunchworld.conf 文件中添加了
AddHandler cgi-script .cgi .py。
2.我已经给了hello.py文件的权限
- 我已将
/etc/apache2/conf-available/crunchworld.conf符号链接到/etc/apache2/conf-enabled
4.我已经在/usr/bin/python2.7 路径上安装了python2.7,我也尝试过使用#!/usr/bin/env python,但还是不行。
查看日志后发现End of script output before headers: hello.py, referer: http://localhost/
感谢您的建议,但它仍然显示 500 内部错误。
【问题讨论】: