简体   繁体   中英

NGINX and PHP Gzip compression not working in browser but works in cURL

There is a peculiar issue happening in my NGinx and PHP Setup.

My Test URL : http://104.194.26.13:2002/a.php

I am using PHP with NGinx (FCGI). To compress the data I am using :

<?php

ob_start('ob_gzhandler');

phpinfo();

?>

When accessed via the browser it shows :

Vary: Accept-Encoding

But there is no Content-Encoding and the size of the downloaded data shown in Firebug is that of a non-compressed data.

When accessed from CLI using curl :

curl -H "Accept-Encoding: gzip" "http://104.194.26.13:2002/a.php"

There are some gbiresh characters suggesting it did encode. If you save the output with the above command the size is 17.5 KB instead of the 75 KB when accessed via the browser.

Here is the full headers received from my a.php file :

Connection: keep-alive
Content-Length: 75550
Content-Type: text/html
Date: Fri, 15 Jan 2016 05:37:43 GMT
Server: nginx
Vary: Accept-Encoding
X-Powered-By: PHP/5.5.27

What could be possibly wrong ?

Which browser are you using, because Chrome 47.0.2526.106 m shows this:

请求

Now, as stated in the comments, why don't you try and compress it directly from Nginx? By leveraging gzip compression within the nginx config:

# enable gzip compression
gzip on;
gzip_min_length  1100;
gzip_buffers  4 32k;
gzip_types    text/plain application/x-javascript text/xml text/css;
gzip_vary on;
# end gzip configuration

Source


Here are my request headers:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Host:104.194.26.13:2002
Referer:http://stackoverflow.com/questions/34805168/nginx-and-php-gzip-compression-not-working-in-browser-but-works-in-curl/34805312?noredirect=1
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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