Ubuntu 14.04 上的 Apache2.4.7 不会执行 Python cgi 文件。该站点改为显示 python 代码

Isa*_*aac 7 python apache2

问题描述:

当我127.0.0.1/cgi-bin/test.cgi在浏览器中加载时,我test.cgi被视为文本文件而不是 python 文件。

排除错误与python代码有关的可能性:

  • 无论我对 python 代码做什么,我都无法得到故意的 500 错误。

  • 我已经通过sudo chmod +x.

  • 我之前在以前版本的 Ubuntu 中做过这个,没有问题。

理论:

我相信问题出在我的配置上。下面是我对两个文件的配置,apache2.conf000-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

<Directory /home/isaac/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

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
Run Code Online (Sandbox Code Playgroud)

/etc/apache2/sites-available/000-default

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /home/isaac/www
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

ScriptAlias /cgi-bin/ /home/isaac/www/cgi-bin/
    <Directory "/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
    </Directory>
Run Code Online (Sandbox Code Playgroud)

mur*_*uru 9

第一个问题是因为 CGI 模块没有被启用,所以 Apache 没有像 CGI 那样处理任何东西。启用它:

sudo a2enmod cgi
Run Code Online (Sandbox Code Playgroud)

在 Apache2.4 中,配置被大量清理,default站点定义中的内容已移至conf-available. 除此之外,这还包括在default旧版本站点中看到的与 CGI 相关的配置行。这些已移至/etc/apache2/conf-available/serve-cgi-bin.conf,其中包含:

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
Run Code Online (Sandbox Code Playgroud)

这就导致了第二个问题。修改该文件,或禁用该配置:

sudo a2disconf serve-cgi-bin
Run Code Online (Sandbox Code Playgroud)

  • 谢谢!我将代码粘贴到 /etc/apache2/conf-enabled/serve-cgi-bin.conf (3认同)