【问题标题】:Apache2 not sending "Content-Type" in headerApache2 未在标头中发送“Content-Type”
【发布时间】:2010-10-12 14:43:45
【问题描述】:

我在 Ubuntu 上安装了标准的 Apache2。

我试图让 mod_deflate 工作,它确实如此,但注意到它没有压缩我的 .js 文件。仔细检查发现 apache 没有发送 Content-Type: 用于 .php 文件以外的任何内容。对他们来说,它发送的是“text/html”,这很奇怪,因为 DefaultType 是“text/plain”。

我不知道这是为什么... mod_mime 已启用,我还没有触及它的配置。

这是我的服务器对 .css 文件的响应示例:

Date    Wed, 11 Mar 2009 04:48:12 GMT
Server  Apache/2.2.9 (Ubuntu)
Connection  Keep-Alive
Keep-Alive  timeout=15, max=96
Etag    "30478-4fb-464bec553a600"
Vary    Accept-Encoding

【问题讨论】:

    标签: apache2 content-type mime


    【解决方案1】:

    这是一个已知问题。是哪个ubuntu版本?

    我刚刚尝试了 ubuntu 8.10 和 debian 5 安装,我还没有接触过 apache 配置。两者都工作正常:

    HTTP/1.x 200 OK
    Date: Wed, 11 Mar 2009 10:25:17 GMT
    Server: Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4 with Suhosin-Patch mod_wsgi/2.3 Python/2.5.2
    Last-Modified: Wed, 11 Mar 2009 10:19:41 GMT
    Etag: "1544ae-12-464d534a6c940"
    Accept-Ranges: bytes
    Content-Length: 18
    Keep-Alive: timeout=15, max=100
    Connection: Keep-Alive
    Content-Type: text/css
    

    【讨论】:

    • cat /etc/lsb-release 给了我 8.10 版
    【解决方案2】:

    看起来这是使用 eTag 缓存项目的结果,而我忽略了这一事实。

    发生的事情是这些项目在浏览器缓存中,实际上并不是从服务器发送的,因此没有 Content-Type。但是,浏览器在对 eTag 进行缓存查找时从服务器接收标头。这就是我所看到的。

    【讨论】:

      【解决方案3】:

      在 httpd.conf 中注释 Content-Type 默认值时,有时会发生这种情况。

      在 Ubuntu 8.04 中,我记得它设置为 text/html。

      【讨论】:

      • 在 httpd.conf 中我发现: DefaultType html/plain ...这很奇怪,它如何为我的 .php 文件获取“text/html”,而不是为 .php 文件获取“text/javascript”。 js 文件,还是我的 .css 文件的“text/css”?
      • 我会想象 PHP 正在注入它。
      • 从 Debian Squeeze 升级到 Debian Wheezy 后发现了这个微妙的错误。 DefaultType(默认情况下)在 Squeeze 中设置为 text/html,在 Wheezy 中设置为 none。查看 Apache 发送的标头后,我意识到 Content-Type 不是从 Wheezy 发送的。这在某些浏览器(例如 IE)中导致了一个奇怪的问题,其中数据文件试图内联呈现。将 DefaultType 改回 text/html,就像在 Squeeze 中一样,修复了导致 IE 提供下载文件的问题。
      • @ChadFeller DefaultType 指令已弃用,这解释了您看到的 none 值。在 Apache 2.3+ 中,DefaultType text/html 将被忽略。您需要改用 AddTypeForceType 指令。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-26
      • 2014-09-08
      • 2014-11-11
      • 1970-01-01
      • 2011-12-04
      • 1970-01-01
      相关资源
      最近更新 更多