NGINX如何使HTTP Basic Auth页面启用Gzip压缩

4

以下是我的gzip设置:

##
  # Gzip Settings
  ##

  gzip on;

  gzip_vary on;
  gzip_proxied any;
  gzip_comp_level 5;
  # Don't compress anything under 256 bytes
  gzip_min_length     256;
  # gzip_buffers 16 8k;
  gzip_http_version 1.1;
  gzip_disable  'MSIE [1-6]\.(?!.*SV1)';
  gzip_types
   application/atom+xml
   application/javascript
   application/json
   application/rss+xml
   application/vnd.ms-fontobject
   application/x-font-ttf
   application/x-font-opentype
   application/x-font-truetype
   application/x-javascript
   application/x-web-app-manifest+json
   application/xhtml+xml
   application/xml
   font/eot
   font/opentype
   font/otf
   image/svg+xml
   image/x-icon
   image/vnd.microsoft.icon
   text/css
   text/plain
   text/javascript
   text/x-component;

curl -IL https://example.com

HTTP/2 401

server: nginx

date: Fri, 28 Dec 2018 14:09:26 GMT

content-type: text/html; charset=UTF-8

content-length: 7326

www-authenticate: Basic realm="Privacy Enabled"

etag: "5c262af8-1c9e"

你可以看到这个页面并没有启用gzip。

如何使401页面启用gzip?


2
我在gzip_types中发现缺少"text/html",你能把它加入到列表中吗? - fiveelements
如果你不想对text/html使用gzip压缩,可以修改401响应的内容类型。 - fiveelements
1
@fiveelements的评论有任何更新吗? - Tarun Lalwani
mimeType text/html 缺失,因此它被排除了,这是100%确定的。 - Sascha Grindau
1个回答

2
在您的curl示例中,类型为text/html,但不在您的gzip_types中。
请将text/html添加到gzip_types中,然后应该可以正常工作。
最初的回答

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接