apache centos无法提供图像-脚本头过早结束 [英] apache centos fails to serve images - premature end of script headers

查看:72
本文介绍了apache centos无法提供图像-脚本头过早结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么我的apache centos服务器无法提供图像.我在error_log文件中看到脚本头过早结束"消息.文本很好用,因为我的perl脚本的第一行是:

I can't figure out why my apache centos server fails to serve images. I see "premature end of script headers" message in the error_log file. Text is served fine as the first line of my perl script is:

#! /usr/bin/perl -w

我发送的第一行是

print "Content-type: text/html\n\n";

文件和文件夹的权限为755.我尝试使用.jpg和.gif文件,但均不起作用.

The permissions on the files and folder is 755. I've tried .jpg and .gif files but neither works.

我添加了

AddType image/gif .gif .GIF
AddType image/jpeg .jpeg .jpg .jpe .JPG

到/etc/httpd/conf/httpd.conf文件. 我已经取消注释同一文件中的"#EnableSendfile off",并重新启动了服务器并刷新了浏览器缓存.什么都没用.

To the /etc/httpd/conf/httpd.conf file. I've uncommented "#EnableSendfile off" in the same file and restarted the server and flushed the browser cache. Nothing worked.

还有其他想法吗?

推荐答案

默认情况下,Apache的httpd.conf文件中包含以下内容:

By Default Apache comes with the following in your httpd.conf file:

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

手册中所述:

ScriptAlias指令告诉Apache为CGI程序预留了一个特定目录. Apache将假定此目录中的每个文件都是CGI程序,并在客户端请求该特定资源时尝试执行该文件.

The ScriptAlias directive tells Apache that a particular directory is set aside for CGI programs. Apache will assume that every file in this directory is a CGI program, and will attempt to execute it, when that particular resource is requested by a client.

这意味着Apache试图通过cgi脚本运行图像文件,从而导致您看到的错误.

This means that Apache is attempting to run your image files a cgi scripts causing the error you see.

有两个选项.

  1. 首选选项是提供非cgi内容,例如来自cgi-bin文件夹外部的图像.例如,使用默认的Web根目录"/var/www/html/"(某些发行版可能会对此进行更改).
  2. 告诉Apache不要将所有文件都当作cgi处理.

替换此:

 ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

与此:

Alias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/cgi-bin/">
   Options +ExecCGI
</Directory>
AddHandler cgi-script .cgi .pl

这篇关于apache centos无法提供图像-脚本头过早结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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