我正在使用位于 nginx 后端服务前面的谷歌云负载均衡器(用谷歌云术语来说)。
当我直接访问 nginx 服务器时,我可以看到“Content-Encoding: gzip” header (左侧)。
但是负载均衡器的响应不包含此 header (右侧)。
我已经在 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/