【发布时间】:2018-10-23 06:48:42
【问题描述】:
我正在使用 apache2 开发 Ubuntu 16.04LTS。我正在执行一个简单的 CGI python 脚本“hello.py”。但不是执行文件,而是下载它。如果我将扩展名从“.py”更改为“.cgi”,代码将显示在我的浏览器中。
我的CGI脚本保存在/var/www/cgi-bin目录下,写在下面
import cgitb
cgitb.enable()
print("Content-Type: text/html;charset=utf-8")
print "Content-type:text/html\r\n\r\n"
print '<html>'
print '<head>'
print '<title>Hello Word - First CGI Program</title>'
print '</head>'
print '<body>'
print '<h2>Hello Word! This is my first CGI program</h2>'
print '</body>'
print '</html>'
我已关注CGI tutorial。本教程遵循 ScriptAlias 方法来配置 apache2。根据教程,我已将以下代码添加到 apche2.conf 文件的末尾
######### Adding capaility to run CGI-scripts #################
ServerName localhost
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
Options +ExecCGI
AddHandler cgi-script .cgi .pl .py
我已将我的 conf-available/serve-cgi-bin.conf 文件更改为以下形式
<IfModule mod_alias.c>
<IfModule mod_cgi.c>
Define ENABLE_USR_LIB_CGI_BIN
</IfModule>
<IfModule mod_cgid.c>
Define ENABLE_USR_LIB_CGI_BIN
</IfModule>
<IfDefine ENABLE_USR_LIB_CGI_BIN>
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin">
AllowOverride None
Options +ExecCGI
#Require all granted
</Directory>
</IfDefine>
</IfModule>
我的 CGI 脚本仍在下载而不是运行。如何解决这个问题?
【问题讨论】:
-
欢迎,看看这里有没有忘记什么:httpd.apache.org/docs/2.4/howto/cgi.html(如
LoadModule) -
感谢您的支持。我已经修好了