Google 云负载平衡器未返回 Content-Encoding:gzip
Google cloud load balancer not returning Content-Encoding: gzip
我正在使用位于 nginx 后端服务前面的 google 云负载平衡器(在 google 云术语中)。
当我直接访问 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;
}
}
相关的 link 无效:
有什么想法吗?
云负载平衡器本身不会压缩或解压缩响应。它们提供由使用 gzip.You need to enable gzip proxied.
压缩的后端实例生成的响应
为了在负载均衡器的响应中包含此 header,在您的 nginx 配置文件中,您可能必须设置 Accept-Encoding header 并修改用户代理以包含this document 中提到的字符串代理。
例如:
Accept-Encoding: gzip
User-Agent: 我的程序 (gzip)
我正在使用位于 nginx 后端服务前面的 google 云负载平衡器(在 google 云术语中)。
当我直接访问 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;
}
}
相关的 link 无效:
有什么想法吗?
云负载平衡器本身不会压缩或解压缩响应。它们提供由使用 gzip.You need to enable gzip proxied.
压缩的后端实例生成的响应为了在负载均衡器的响应中包含此 header,在您的 nginx 配置文件中,您可能必须设置 Accept-Encoding header 并修改用户代理以包含this document 中提到的字符串代理。
例如:
Accept-Encoding: gzip
User-Agent: 我的程序 (gzip)