【问题标题】:Lighttpd - Error while trying to run C application through CGILighttpd - 尝试通过 CGI 运行 C 应用程序时出错
【发布时间】:2017-09-27 04:28:24
【问题描述】:

问候各位程序员,

我是新来的,所以请温柔一点。

现在的问题是,我目前正在使用嵌入式 linux 在 WAGO PLC (750-8202) 上运行动态 Web 应用程序。 Lighttpd 安装在 PLC 本身上。目标是通过 Web 应用程序监控/编辑 PLC 的 I/O。

经过大量研究后,我发现我需要使用 CGI 与我的 C 应用程序进行通信,这些应用程序可以从 PLC 返回我需要的信息。我尝试了一些简单的 hello world 代码,但总是出错。

这是我的 lighttpd.conf

# Common configuration values.
server.document-root    = "/var/www"
server.username         = "www"
server.groupname        = "www"
server.tag              = "lighttpd"
server.errorlog         = "/var/log/lighttpd/error.log"
accesslog.filename      = "/var/log/lighttpd/access.log"

index-file.names        = ( "index.html", "index.php" )
server.modules          = (
    "mod_access",
    "mod_accesslog",
    "mod_cgi",
    "mod_fastcgi",
    "mod_rewrite",
    "mod_redirect",
    "mod_auth",
    "mod_proxy"
)

include "mode.conf"
include "mime_types.conf"
include "mod_fastcgi.conf"
include "auth.conf"
include "redirect_test.conf"

$HTTP["url"] =~ "/cgi-bin/" {
        cgi.assign = ( "" => "" )
}

cgi.assign      = (
        ".cgi"  => ""
)
url.rewrite-once = (
  # Codesys3 webvisu forces the browser to come out with POST requests to the root context.
  # Move that to the /webvisu/ context so it goes through the proxy 8000.
  "^/WebVisuV3.bin" => "/webvisu/WebVisuV3.bin",
  # Redirect all http[s]://<ip>/rest/ URL's to the RESTful API Example "/rest/index.php'  
  "^(?:.*)/rest/(.*)" => "/rest/index.php/$1"
)

# Transfer all http[s]://<ip>/webvisu/ URL's to the proxy server on port 8000.
# That is, all codesys webvisu traffic goes through the proxy.
#$HTTP["url"] =~ "^/webvisu/.*" {
#    proxy.server = ("" => (( "host" => "127.0.0.1", "port" => proxy_port )) )
#}

# Activate proxy server on port 8000. Sends all requests from the browser to
# the codesys webserver (localhost:8080).
$SERVER["socket"] == "127.0.0.1:" + proxy_port {
    url.rewrite-once = (
        "^/webvisu/$" => "/webvisu.htm",
        "^/webvisu/(.*)" => "/$1"
    ),
    proxy.server = ( "" => (( "host" => "127.0.0.1", "port" => 8080 )) )
}

现在我正在尝试用 C 编写一个简单的应用程序:

#include <stdio.h> 
int main(void) 
{ 
printf("Content-Type: text/plain;charset=us-ascii\n\n");
printf("Hello world\n\n");  
return 0; 
}

我这样称呼我的应用程序:

http://192.168.1.2/cgi-bin/foo.cgi

而且只得到一个空白页。如果我检查错误日志,它会给我这个错误:

(mod_cgi.c.1341) cleaning up CGI: process died with signal 6 

谁能指出我在哪里犯了某种错误?还是我做错了?是否有其他更好的方式与 C 应用程序通信?我花了几天时间试图弄清楚,现在我真的很失望。任何形式的帮助将不胜感激。

非常感谢,祝您有美好的一天!

【问题讨论】:

  • 信号 6 是 SIGABRT,如果没有进一步的信息,这可能意味着太多。您是否尝试注释掉代理的东西?您是否使用适合您的硅胶的正确编译器编译 foo.cgi?您是否尝试了一个简单的 shell 脚本(当然,如果有可用的 shell),其中只包含 #!/bin/shecho Hello World! 行?
  • 我尝试了你建议的一个简单的 shell 脚本,它工作正常。尝试注释掉代理的东西没有结果,所以我仍然坚持使用我的 C 脚本。我用'gcc foo.c -o foo.cgi'编译了cgi程序
  • 你让我走上了正轨,我使用了错误的编译器,现在它可以完美运行了。非常感谢!现在关闭这个帖子。
  • 您可以而且应该回答您自己的问题。其他人可能有同样的问题。是的,如果语法和拼写还不错,我会赞成这个答案。

标签: c web-applications cgi embedded-linux lighttpd


【解决方案1】:

感谢 deamentiaemundi,我得到了它的工作。我使用了错误的编译器,PLC 有一个 ARM 处理器,需要使用 Wago 提供的工具 - ptxdist 编译代码。

【讨论】:

    猜你喜欢
    • 2021-06-26
    • 1970-01-01
    • 2019-04-02
    • 2017-07-15
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    • 2017-07-20
    • 2021-09-20
    相关资源
    最近更新 更多