Ubuntu 14.04上的Apache2.4.7不会执行Python cgi文件。 该站点显示python代码
问题描述:
当我在浏览器中加载127.0.0.1/cgi-bin/test.cgi
,我的test.cgi
被视为文本文件而不是python文件。
排除错误与python代码相关的可能性:
-
无论我对python代码做什么,我都无法得到故意的500错误。
-
我已经通过
sudo chmod +x
使cgi文件可执行。 -
我之前在Ubuntu的早期版本中完成了这个问题。
理论:
我相信问题在于我的配置。 下面是我配置的两个文件, apache2.conf
和000-default
。
我一直在粘贴不同的东西,以使我的配置文件工作,我得到的每一次机会。 这只是这两个文件在撰写本文时的样子的快照。
先感谢您!
/etc/apache2/apache2.conf
:
Mutex file:${APACHE_LOCK_DIR} default PidFile ${APACHE_PID_FILE} Timeout 300 KeepAlive On MaxKeepAliveRequests 100 KeepAliveTimeout 5 User ${APACHE_RUN_USER} Group ${APACHE_RUN_GROUP} HostnameLookups Off ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn IncludeOptional mods-enabled/*.load IncludeOptional mods-enabled/*.conf Include ports.conf Options Indexes FollowSymLinks AllowOverride None Require all granted AccessFileName .htaccess Require all denied LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %O" common LogFormat "%{Referer}i -> %U" referer LogFormat "%{User-agent}i" agent IncludeOptional conf-enabled/*.conf IncludeOptional sites-enabled/*.conf
/etc/apache2/sites-available/000-default
:
ServerAdmin webmaster@localhost DocumentRoot /home/isaac/www ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined ScriptAlias /cgi-bin/ /home/isaac/www/cgi-bin/ AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all AddHandler cgi-script .py AddHandler default-handler .html .htm
第一个问题是因为CGI模块尚未启用,因此Apache不会将任何内容处理为CGI。 能够它:
sudo a2enmod cgi
在Apache2.4中,配置已大大清理, default
站点定义中的内容已移至配置文件中。 除此之外,还包括在旧版本的default
站点中看到的与CGI相关的配置行。 这些已移至/etc/apache2/conf-available/serve-cgi-bin.conf
,其中包含:
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
这导致了第二个问题。 修改该文件,或禁用该配置:
sudo a2disconf serve-cgi-bin