Lighttpd - 尝试通过CGI运行C应用程序时出错

时间:2017-04-29 00:30:08

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

问候其他程序员,

我在这里有点新意,所以请保持温和。

现在问题是,我目前正在使用嵌入式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应用程序进行通信?我失去了好几天试图搞清楚,现在我真的失望了。任何形式的帮助将不胜感激。

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

1 个答案:

答案 0 :(得分:1)

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