http - Google 云负载均衡器未返回内容编码 : gzip

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

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

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

但是负载均衡器的响应不包含此 header (右侧)。

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

有什么想法吗?

最佳答案

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

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

例如:

接受编码:gzip

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

关于http - Google 云负载均衡器未返回内容编码 : gzip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51932121/

相关文章:

javascript - Promise 在解决之前不等待嵌套 promise

linux - Nginx 配置添加 www 忽略请求 uri

azure - Google Cloud 相当于 Azure 特权身份管理 (PIM)

python - 如何从 tensorflow 中的谷歌存储桶中读取文件?

node.js - 使用 Nginx 作为 Node.js 的代理向 favicon.ico 添加 Expires header

deployment - 谷歌云部署管理器 : How to set up IAM when creating bucket

java - 如何访问服务器端的内容?

angularjs - 嵌套 REST 资源的 Angular ui-router 状态名称

apache - 重写规则不起作用

CSS 未加载,因为它的 MIME 类型