用户目录“标头之前的脚本输出结束"中的Apache CGI. [英] Apache CGI in user directory "End of script output before headers"

查看:247
本文介绍了用户目录“标头之前的脚本输出结束"中的Apache CGI.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有关此主题的一些问题,但似乎没有一个问题可以解决我的问题.参见.

我在Linux,Fedora21上,并且尝试启用每个用户目录的CGI脚本.我遵循了这些的说明,但没有成功.

我得到了错误:

[cgi:error] End of script output before headers: test.cgi

test.cgi是可执行的sh文件,包含一个非常简单的脚本:

#!/usr/bin/sh

echo "Content-type: text/plain"
echo ""
echo "Hello"

具有可执行标志,并且从shell运行没有问题. 我也尝试使用Python:相同的结果.

我也很好地禁用了selinux.

我还尝试将debug级别设置为Apache的ErrorLog,但是我得到的只是上述错误之前的授予"权限.

我还用

<Directory "/home/*/public_html">
    AllowOverride All
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require all granted
</Directory>

<Directory /home/*/public_html/cgi-bin/>
    Options ExecCGI FollowSymLinks
    SetHandler cgi-script
    AddHandler cgi-script .cgi .exe .pl .py .vbs
    Require all granted
    AllowOverride All
</Directory>

配置了/etc/httpd/conf.d/userdir.conf文件

<Directory "/home/*/public_html">
    AllowOverride All
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require all granted
</Directory>

<Directory /home/*/public_html/cgi-bin/>
    Options ExecCGI FollowSymLinks
    SetHandler cgi-script
    AddHandler cgi-script .cgi .exe .pl .py .vbs
    Require all granted
    AllowOverride All
</Directory>

,然后重新启动服务器.没有成功一切对我来说都很好,我听不懂...怎么了??

我忘了补充一点,该问题仅针对每个用户目录:如果我将相同的脚本移至/var/www/cgi-bin目录,它将按预期工作.

该外壳确实存在:

$ ls /usr/bin/sh
/usr/bin/sh

解决方案

最后,我解决了这个问题.感谢@JimB,因为在他的评论他指出了SUEXEC,我对此一无所知(或者直到现在才被忽略).

在阅读了 suEXEC文档之后,我理解了问题所在到那里.所以,我看了一下配置:

# suexec -V
 -D AP_DOC_ROOT="/var/www"
 -D AP_GID_MIN=1000
 -D AP_HTTPD_USER="apache"
 -D AP_LOG_SYSLOG
 -D AP_SAFE_PATH="/usr/local/bin:/usr/bin:/bin"
 -D AP_UID_MIN=1000
 -D AP_USERDIR_SUFFIX="public_html"

,一切看起来都很好(对我的用户而言,良好的uid/gid,userdir_suffix很好,等等).所以我看了看系统日志:

# journalctl -b | grep "suexec"
May 22 11:43:12 caladan suexec[5397]: uid: (1000/user) gid: (1000/user) cmd: test.cgi
May 22 11:43:12 caladan suexec[5397]: directory is writable by others: (/home/user/public_html/cgi-bin)

那是问题:我的 cgi-bin目录可被其他人写入.

我通过简单地将权限更改为755来解决.

I know there are some questions about this topic, but none seems to solve my issue. See this or this or this.

I'm on Linux, Fedora21, and I'm trying to enable per user directory CGI script. I followed these instructions, but without success.

I get the error:

[cgi:error] End of script output before headers: test.cgi

test.cgi is an executable sh file, containing a very simple script:

#!/usr/bin/sh

echo "Content-type: text/plain"
echo ""
echo "Hello"

which has executable flag and runs without problems from shell. I also tried with Python: same result.

I also disabled selinux for good measure.

I also tried setting the debug level to Apache's ErrorLog, but all I get is only "granted" permissions before the error above.

I also configured the /etc/httpd/conf.d/userdir.conf file with

<Directory "/home/*/public_html">
    AllowOverride All
    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    Require all granted
</Directory>

<Directory /home/*/public_html/cgi-bin/>
    Options ExecCGI FollowSymLinks
    SetHandler cgi-script
    AddHandler cgi-script .cgi .exe .pl .py .vbs
    Require all granted
    AllowOverride All
</Directory>

and restarted the server. No success. Everything looks fine to me, I can't understand... What's wrong??

EDIT:

I forgot to add that the issue is just for per-user directory: if I move the same script to /var/www/cgi-bin directory, it works as expected.

EDIT 2:

The shell does exist:

$ ls /usr/bin/sh
/usr/bin/sh

解决方案

Finally I solved that. Thanks to @JimB, because in his comment he pointed out SUEXEC, which I didn't know about (or simply ignored till now).

After reading a bit the suEXEC documentation, I understood the the problem had to be there. So, I took a look at the configuration:

# suexec -V
 -D AP_DOC_ROOT="/var/www"
 -D AP_GID_MIN=1000
 -D AP_HTTPD_USER="apache"
 -D AP_LOG_SYSLOG
 -D AP_SAFE_PATH="/usr/local/bin:/usr/bin:/bin"
 -D AP_UID_MIN=1000
 -D AP_USERDIR_SUFFIX="public_html"

and everything looked Ok (good uid/gid for my user, userdir_suffix is fine, etc). So I took a look at the system logs:

# journalctl -b | grep "suexec"
May 22 11:43:12 caladan suexec[5397]: uid: (1000/user) gid: (1000/user) cmd: test.cgi
May 22 11:43:12 caladan suexec[5397]: directory is writable by others: (/home/user/public_html/cgi-bin)

and that's the problem: my cgi-bin directory was writable by others.

I fixed by simply changing the permissions to 755.

这篇关于用户目录“标头之前的脚本输出结束"中的Apache CGI.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆