简体   繁体   English

Apache2 未在 header 中发送“Content-Type”

[英]Apache2 not sending “Content-Type” in header

I have a standard Apache2 installation on Ubuntu.我在 Ubuntu 上有一个标准的 Apache2 安装。

I was trying to get mod_deflate to work, which it does, but noticed it was not gzipping my.js files.我试图让 mod_deflate 工作,它确实如此,但注意到它没有压缩 my.js 文件。 A closer inspection revealed that apache isn't sending Content-Type: for anything other than.php files .仔细检查发现apache 没有发送 Content-Type: 用于除.php 文件之外的任何内容 For them it's sending "text/html," which is strange since DefaultType is "text/plain."对他们来说,它发送的是“text/html”,这很奇怪,因为 DefaultType 是“text/plain”。

I have no clue why this is... mod_mime is enabled and I haven't touched the configs for it.我不知道这是为什么... mod_mime 已启用,我还没有触及它的配置。

Here's an example response from my server for a.css file:这是我的服务器对 .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

It looks like this was a result of the item being cached using eTags, and my overlooking that fact.看起来这是使用 eTags 缓存项目的结果,而我忽略了这一事实。

What was happening was that this these items were in the browser cache, and were not actually being sent from the server, thus there was no Content-Type.发生的事情是这些项目在浏览器缓存中,实际上并不是从服务器发送的,因此没有 Content-Type。 However, the browser was receiving headers from the server while doing the cache lookup on the eTag.. this is what I was seeing.但是,浏览器在对 eTag 进行缓存查找时从服务器接收标头。这就是我所看到的。

This happen some times when Content-Type default value is commented in httpd.conf.当在 httpd.conf 中注释 Content-Type 默认值时,有时会发生这种情况。

In Ubuntu 8.04 it is set to text/html as I remember.我记得在 Ubuntu 8.04 中它设置为 text/html。

It's a known problem.这是一个已知问题。 Which ubuntu version is it? ubuntu是哪个版本?

I just tried on ubuntu 8.10 and debian 5 installations where I havent touched the apache configuration.我刚刚尝试了 ubuntu 8.10 和 debian 5 安装,我还没有触及 apache 配置。 Both work fine:两者都工作正常:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM