【问题标题】:CGI script not workingCGI 脚本不工作
【发布时间】:2018-01-03 20:34:48
【问题描述】:

当我尝试在浏览器中运行 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 之前。我已经尝试了所有方法,如果有人可以为我解决这个问题,那就太好了;)

【问题讨论】:

  • 你有权限运行脚本invoker.cgi吗?
  • ls -l 检查脚本是否有执行权限
  • 确保您的文件invoker.cgi 具有Apache 进程的执行权限(还要检查它没有写权限)。确保文件有 linux 行结尾(不是 DOS)。确保 suexec 没有搞砸。
  • @SQLHacks 如何为 Apache 进程授予执行权限

标签: java linux apache cgi sh


【解决方案1】:

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

【讨论】:

  • 当我输入“localhost:80/cgi/invoker.cgi”时,浏览器开始下载文件而不是显示 HTML
猜你喜欢
  • 2012-10-15
  • 2017-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-23
  • 1970-01-01
相关资源
最近更新 更多