gzip_http_version set to 1.0 but sends 1.1

user715564 asked:

I am trying to set Amazon CloudFront up with Nginx using W3 Total Cache and WordPress multisite. CloudFront only works with http 1.0 so, I read that you need to change the http version in gzip to 1.0. I made the change but my headers are still using http 1.1. Here is gzip block:

gzip  on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.0;
gzip_disable "MSIE [1-6].(?!.*SV1)";
gzip_types text/plain text/css application/json application/x-javascript text/xml
                    application/xml application/xml+rss text/javascript;

Here is my complete nginx.conf file:

events {
 worker_connections 5120; # increase for busier servers
 use epoll; # you should use epoll here for Linux kernels 2.6.x
}
http {
 server_name_in_redirect off;
 server_names_hash_max_size 10240;
 server_names_hash_bucket_size 1024;
 include    mime.types;
include    /etc/nginx/fastcgi.conf;
 default_type  application/octet-stream;
 server_tokens off;
# remove/commentout disable_symlinks if_not_owner;if you get Permission denied error
# disable_symlinks if_not_owner;
 sendfile on;

 gzip  on;
 gzip_vary on;
 gzip_proxied any;
 gzip_comp_level 6;
 gzip_buffers 16 8k;
 gzip_http_version 1.0;
 gzip_disable "MSIE [1-6].(?!.*SV1)";
 gzip_types text/plain text/css application/json application/x-javascript text/xml
                        application/xml application/xml+rss text/javascript;

 limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

 tcp_nopush on;
 tcp_nodelay on;
 keepalive_timeout  5;
 ignore_invalid_headers on;
 client_header_timeout  3m;
 client_body_timeout 3m;
 send_timeout     3m;
 reset_timedout_connection on;
 connection_pool_size  256;
 client_header_buffer_size 256k;
 large_client_header_buffers 4 256k;
 client_max_body_size 200M;
 client_body_buffer_size 128k;
 request_pool_size  32k;
 output_buffers   4 32k;
 postpone_output  1460;
 proxy_temp_path  /tmp/nginx_proxy/;
 client_body_in_file_only on;
 log_format bytes_log "$msec $bytes_sent .";
 include "/etc/nginx/vhosts/*";
}

Is there something else I need to change? If I need to provide anymore details please let me know.

Here are the headers.

HTTP/1.1 200 OK => 
Server => nginx admin
Date => Mon, 04 Mar 2013 01:39:33 GMT
Content-Type => text/html; charset=UTF-8
Connection => close
X-Powered-By => PHP/5.3.21
Expires => Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control => no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma => no-cache
X-Pingback => http://website.com/xmlrpc.php
Set-Cookie => PHPSESSID=c593560b5c75dee9b9c1032416ebbd30; path=/
X-Cache => HIT from Backend

My answer:


Amazon CloudFront sends an HTTP/1.0 request to your origin server, which causes nginx to refuse to send a gzipped response (by default). Setting gzip_http_version 1.0; works around this broken behavior in CloudFront. (It’s been 15 years since HTTP/1.1, anything still speaking HTTP/1.0 is fundamentally broken…)

However, once you set it and reload nginx, you also need to invalidate your objects in CloudFront so that new (gzipped) copies will be fetched.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.