在浏览器上运行python CGI脚本,生成脚本代码不是预期的输出



我正在尝试运行一个小的CGI脚本,但它在浏览器而不是HTML上显示脚本代码。我正在运行Apache服务器,它是根据要求配置的。

DocumentRoot "/home/user/htdocs"
<Directory "/home/user/htdocs">
   Options Indexes FollowSymLinks
   Options +ExecCGI
   AddHandler cgi-script .cgi .py
   Order allow,deny
   Allow from all
   AllowOverride None
   Require all granted
</Directory>
ScriptAlias /cgi-bin/ /home/user/cgi-bin/

我已经将脚本放在 cgi-bin 目录中并赋予它可执行权限( chmod 755),但它仍然无法正常工作。

我错过了什么?

问题是你没有告诉Apache允许你在CGI文件夹中运行CGI脚本。基本上你对/home/user/cgi-bin文件夹的设置是什么,Debian 在他们的安装中将其作为默认设置(不过我改变了路径):

<Directory "/home/user/cgi-bin">
  AllowOverride None
  Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  Order allow,deny
  Allow from all
</Directory>

最新更新