相关疑难解决方法(0)

在 Apache 中启用 gzip 压缩时未发送内容长度?

我真的很感激能帮助理解这种 Apache 行为。

我正在从应用程序/json 中的 iPhone Objective-C 应用程序与 PHP 通信。Gzip 压缩在服务器上启用,并由客户端请求。

从我的.htaccess:

AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php application/json
Run Code Online (Sandbox Code Playgroud)

对于小型请求,Apache 正在设置“Content-Length”标头。例如(这些值在 Objective-C 中从标头输出):

Connection = "Keep-Alive";
"Content-Encoding" = gzip;
"Content-Length" = 185;     <-------------
"Content-Type" = "application/json";
Date = "Wed, 22 Sep 2010 12:20:27 GMT";
"Keep-Alive" = "timeout=3, max=149";
Server = Apache;
Vary = "Accept-Encoding";
"X-Powered-By" = "PHP/5.2.13";
"X-Uncompressed-Content-Length" = 217;
Run Code Online (Sandbox Code Playgroud)

X-Uncompressed-Content-Length是我添加的标头,设置为未压缩 JSON 字符串的大小。

如您所见,此请求非常小(217 字节)。

这是来自较大请求(282888 字节)的标头:

Connection = "Keep-Alive";
"Content-Encoding" = gzip;
"Content-Type" = "application/json";
Date = "Wed, …
Run Code Online (Sandbox Code Playgroud)

php compression gzip apache-2.2

14
推荐指数
3
解决办法
4万
查看次数

Apache/2.2.20 (Ubuntu 11.10) gzip 压缩在 php 页面上不起作用,内容被分块

我正在将项目转移到新生产服务器时遇到问题。PHP 应用程序的 HTML 输出没有被 Apache mod_deflate 模块压缩。其他资源,如样式表和 javascript 文件,甚至与 PHP 输出具有相同内容类型 (text/html) 的 html 页面,都被压缩了!

项目在 .htaccess 中使用以下规则(来自 HTML5 样板):

<IfModule mod_deflate.c>
  # 对损坏的标头强制放气 developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
  <IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
      SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~ -]{4,13}$ HAVE_Accept-Encoding
      RequestHeader 附加 Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
    </IfModule>
  </IfModule>

  # HTML、TXT、CSS、JavaScript、JSON、XML、HTC:
  <IfModule filter_module>
    过滤声明压缩
    FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html
    FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css
    FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain
    FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml
    FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component
    FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript
    FilterProvider COMPRESS DEFLATE resp=Content-Type …

php compression deflate apache-2.2

5
推荐指数
1
解决办法
1492
查看次数

标签 统计

apache-2.2 ×2

compression ×2

php ×2

deflate ×1

gzip ×1