【问题标题】:Google cloud load balancer not returning Content-Encoding: gzip谷歌云负载均衡器不返回内容编码:gzip
【发布时间】:2019-01-26 15:57:05
【问题描述】:

我正在使用位于 nginx 后端服务前面的谷歌云负载均衡器(在谷歌云术语中)。

当我直接访问 nginx 服务器时,我可以看到 'Content-Encoding: gzip' 标头(左侧)。

但来自负载均衡器的响应不包含此标头(右侧)。

我已经在我的 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

有什么想法吗?

【问题讨论】:

  • 使用gzip_static always,甚至可能在server而不是location中。
  • 还是一样。

标签: http nginx google-cloud-platform load-balancing


【解决方案1】:

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

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

例如:

接受编码:gzip

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-18
    • 2020-12-31
    • 1970-01-01
    • 2019-10-04
    • 1970-01-01
    • 2018-06-20
    • 1970-01-01
    相关资源
    最近更新 更多