CGI脚本不起作用

时间:2018-01-03 20:34:49

标签: java linux apache cgi sh

当我尝试在浏览器中运行CGI脚本时, /var/log/apache2/error.log 文件说:

[Wed Jan 03 22:12:36.302682 2018] [cgi:error] [pid 5308] [client
::1:54384] AH01215: (13)Permission denied: exec of
'/var/www/cgi/invoker.cgi' failed: /var/www/cgi/invoker.cgi

我的.cgi文件位于 / var / www / cgi 文件夹中,包含:

#!/bin/bash 
java Main

Main.java 包含(它在“javac Main.java”之后创建一个.class文件):

public class Main {

    public static void main(String[] args) {

        String content = "Content-Type:html/css\n\n";
        String html = "<html>\n" +
                "<body>\n" +
                "<h1>Hi, what's up?</h1>\n" +
                "</body>\n" +
                "</html>";
        System.out.println(content);
        System.out.println(html);
    }
}

/etc/apache2/ports.conf 包含:

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80 

<IfModule ssl_module>    

Listen 443  

</IfModule> 

<IfModule mod_gnutls.c> 

Listen 443  

</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

/etc/apache2/apache2.conf 的顶部,我添加了:

ServerName localhost

/etc/apache2/sites-enabled/000-default.conf 包含:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


ScriptAlias /cgi/ /var/www/cgi/
<Directory "/var/www/cgi">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

此外,.cgi文件应该是.cgi还是.sh以及为什么当我将其设置为可执行文件时,浏览器会开始下载它,而不是显示HTML?我做了这个工作,但是在我重新安装Linux Mint之前。我已经尝试了一切,如果有人可以为我解决这个问题,那就太好了;)

1 个答案:

答案 0 :(得分:1)

使用chmod 755 /var/www/cgi/invoker.cgi使脚本可执行。