不带扩展名执行CGI文件

时间:2017-04-04 18:05:25

标签: linux apache tcl cgi

我是CGI或Apache的新手。

我正在尝试安装名为mooshak的应用程序。

安装完成正常。但是当我打开本地站点时,它只是下载文件而不是执行它。

当我打开http://localhost/~mooshak/cgi-bin/execute时,它只是下载文件,如下所示:

#!/bin/sh
# the next line restarts using tclsh \
PATH=$PATH:/usr/local/bin:/usr/contrib/bin  ; exec tclsh "$0" "$@"

#-*-Mode: TCL; iso-accents-mode: t;-*-  

set errorCode NONE

cd ../..

lappend auto_path packages

source .config

execute::command_line

我的/etc/apache2/mods-enabled/userdir.conf文件如下所示:

<IfModule mod_userdir.c>
        <Directory /home/*/public_html/cgi-bin>
                Options +ExecCGI -Includes -Indexes
                SetHandler cgi-script
                Order allow,deny
                Allow from all
        </Directory>
</IfModule>

我该怎么办?

2 个答案:

答案 0 :(得分:0)

试试这个

<Directory /home/*/public_html>
         Options -Includes -Indexes
         Order allow,deny
         Allow from all
</Directory>
<Directory /home/*/public_html/cgi-bin>
         Options +ExecCGI -Includes -Indexes
         SetHandler cgi-script
</Directory>

并提供给脚本chmod +x

答案 1 :(得分:0)

尝试将/urs/lib/cgi-bin用于cgi脚本。如果你不知道该怎么做,其他任何东西都会给你一个haedache。

对于用户www-data

,cgi脚本需要可执行可读

对于Apache版本&gt; = 2.2,您需要在/etc/apache2/conf-available中添加一个条目。我的配置看起来像这样......

admin@suse:~$ cat /etc/apache2/conf-available/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/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            AllowOverride AuthConfig
                AuthType Basic
                AuthName "Suleiman's Heimat 2.0"
                AuthBasicProvider file
                AuthUserFile /etc/apache2/passwd
                Require valid-user
        </Directory>
    </IfDefine>
</IfModule>

这些是Debian系统的默认设置,以及额外的密码保护。

然后你拨打a2enconf cgi-bin

这与/etc/apache2/mods-enabled无关!我找不到将cgi-code放在那里的理由。相反,您需要通过

激活公共网关接口
a2enmod cgi

这将在/etc/apache2/mods-enabled中添加一个条目。

最后但并非最不重要的是,您需要通过/etc/init.d/apache2 restart

重启服务器

你走了。
希望这会有所帮助。

<强>加成

在重新启动服务器之前,您应该运行apache2ctl configtest来检查配置!

当事情发生时,

/var/log/apache2/也有很好的信息 您还可以使用命令systemctl status apache2.service检查服务的状态,并使用journalctl -b -n 30 -u apache2.service获取最近30个协议条目。