我正在尝试使用 W3 Total Cache 和 WordPress 多站点将 Amazon CloudFront 与 Nginx 一起设置。CloudFront 仅适用于 http 1.0,因此,我了解到您需要将 gzip 中的 http 版本更改为 1.0。我进行了更改,但我的标头仍在使用 http 1.1。以下是 gzip 块:
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;
这是我的完整 nginx.conf 文件:
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/*";
}
我还需要更改其他内容吗?如果我需要提供更多详细信息,请告诉我。
以下是标题。
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
答案1
Amazon CloudFront 向您的源服务器发送 HTTP/1.0 请求,这会导致 nginx 拒绝发送 gzip 压缩的响应(默认情况下)。设置gzip_http_version 1.0;
可以解决 CloudFront 中的这种错误行为。(自 HTTP/1.1 以来已经 15 年了,任何事物仍然认为 HTTP/1.0 从根本上来说已经失效了...)
但是,一旦你设置它并重新加载 nginx,你还需要使 CloudFront 中的对象无效这样就可以获取新的(gzip 压缩的)副本。