我有一个nginx服务器,其中包含一个输出大型json的php脚本 . 我想最小化网络带宽负载并使用Gzip加速我的应用程序并将gzip压缩包从我的服务器传递到客户端浏览器 .

我找到了2个可能的解决方案:1 . 在PHP脚本级别:

// Fetch some data
$data = get_data();

// Turn on output buffering with the gzhandler
ob_start('ob_gzhandler');

// Output as normal
echo json_encode($data);
  • 在nginx服务器级别通过对配置文件进行以下更改

#gzip on; gzip_proxied any; gzip_types text / plain text / css application / json application / x-javascript text / xml application / xml application / xml rss text / javascript; gzip_vary on; gzip_disable“MSIE [1-6] . (?! . * SV1)”; #

我的问题是,如果我在nginx级别进行更改,我是否还需要在php脚本级别使用gzip?它们是相互排斥的策略还是相互依存的 . 我有一点困惑

问候