C 程序(编译为 fcgi)给出 500 内部错误

标签 c linux fastcgi webmin

我正在尝试从我的浏览器运行一个简单的 fcgi 程序(用于测试目的)。

我从这里获取代码:(fcgi 不是 cgi) Run a C Program on a Linux Server

我将 HTTP header 末尾的\n\n 替换为\n\r\n\r。

我还确保 http.conf 具有以下 VirtualHost:

<VirtualHost [snip]>
SuexecUserGroup "#502" "#502"
ServerName [snip]
ServerAlias [snip]
ServerAlias [snip]
ServerAlias [snip]
DocumentRoot /[snip]/public_html
ErrorLog /var/log/virtualmin/[snip].com_error_log
CustomLog /var/log/virtualmin/[snip].com_access_log combined
ScriptAlias /cgi-bin/ /[snip]/[snip].com/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /[snip]/[snip].com/public_html>
    Options -Indexes +IncludesNOEXEC +SymLinksifOwnerMatch +ExecCGI
    allow from all
    AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
    AddHandler fcgid-script .php
    AddHandler fcgid-script .php5
    AddHandler fcgid-script .fcgi
    FCGIWrapper /[snip]/fcgi-bin/php5.fcgi .php
    FCGIWrapper /[snip]/fcgi-bin/php5.fcgi .php5
</Directory>
<Directory /[snip]/cgi-bin>
    allow from all
    AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>
RewriteEngine on
RewriteCond %{HTTP_HOST} =webmail.[snip].com
RewriteRule ^(.*) https://[snip]:20000/ [R]
RewriteCond %{HTTP_HOST} =admin.[snip]
RewriteRule ^(.*) http://[snip]:10000/ [R]
RemoveHandler .php
RemoveHandler .php5
php_admin_value engine Off
IPCCommTimeout 31
FcgidMaxRequestLen 1073741824
</VirtualHost>

我只为 fcgi 文件添加了处理程序行,其余的是在创建子域时由 Virtualmin 生成的。

我一直在搜索过去的 2 小时,并进行了一些实验,但没有任何好的结果。我总是收到 500 Internal Server Error。

错误日志:

[Mon Feb 03 18:16:39 2014] [warn] [client SNIP] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Mon Feb 03 18:16:39 2014] [error] [client SNIP] Premature end of script headers: pibell_server.fcgi

非常感谢。

最佳答案

以下摘自原问题:

@grebneke 事实证明,权限实际上是不正确的!

这可能会帮助其他人:

  1. 确保脚本从命令行运行(感谢@grebneke!)

  2. 我应用了以下命令来正确设置权限:

    [root@s1 cgi-bin]# chmod a+rx file.fcgi

    [root@s1 cgi-bin]# chown yourapacheuser:yourapacheuser file.fcgi

顺便说一句,我从 mysite.com/cgi-bin/file.fcgi 运行了文件。 不确定这是否是强制性的,但我的虚拟主机中也有这个:

AddHandler fcgid-script .fcgi

关于C 程序(编译为 fcgi)给出 500 内部错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21531263/

相关文章:

c - 谐波平均产生不正确的结果

c - unsigned long long int 奇怪的行为

linux - 配置 Makefile 以生成 .a 库而不是 .lib

python - 如何防止 Django 中的 FCGI 请求超时

在更改数组内容时通过位于数组中的指针调用函数

C 套接字读取太多数据

c# - 在 Linux 中运行用 Mono 编译的 C# 程序

linux - 将 .sql 文件导入 MongoDB,重复此操作 1000 次

c++ - 获取 FastCGI 中的所有客户端 header (C/C++)

perl - NGINX 不执行 perl 脚本?