首页 文章

Google Cloud 负载均衡器未返回Content-Encoding:gzip

提问于
浏览
0

我正在使用位于nginx后端服务前面的谷歌 Cloud 负载均衡器(以谷歌 Cloud 计算术语) .

When i'm accessing the nginx server directly i can see the 'Content-Encoding: gzip' header (left side).

But the response from the Load balancer doesn't contain this header (right side).

enter image description here

我在我的nginx配置文件中启用了gzip_proxied:

server {

   listen 80;
    gzip on;
    gzip_vary on;
    gzip_proxied any;  // <------ Here
    gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/rss+xml image/svg+xml;

    access_log  /var/log/nginx/access.log;
    error_log   /var/log/nginx/error.log;

    root /usr/share/nginx/html;
    index index.html index.htm;

    location / {
        gzip_static on;
        if ($http_x_forwarded_proto = "http") {
            return 301 https://$host$request_uri;
        }
        try_files $uri $uri/ /index.html;
    }
}

无效的相关链接:

Google Cloud HTTP Balancer and gzip

有任何想法吗?

1 回答

  • 1

    Cloud 负载均衡器本身不压缩或解压缩响应 . 它们提供由使用gzip压缩的后端实例生成的响应 . 您需要启用gzip proxied .

    为了在负载均衡器的响应中包含此标头,在您的nginx配置文件中,您可能必须设置Accept-Encoding标头并修改用户代理以包含this document中提到的字符串代理 .

    例如:

    Accept-Encoding:gzip

    用户代理:我的程序(gzip)

相关问题