2016-11-09 125 views
0

首先:我对Nginx没有多少经验。当Vary头部不被忽略时,Nginx无法缓存

我就直接进入到这个问题,但:

Nginx的配置:

user www-data; 
    worker_processes auto; 
    pid /run/nginx.pid; 
    events { 
     worker_connections 2048; 
     multi_accept on; 
    } 
    http { 
    proxy_cache_path /var/nginx_cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=10g; 

upstream server { 
    server -removed-; 
} 

server { 
    listen 80; 
    server_name -removed-; 
    location/{ 
      gzip on; 
      gzip_disable "MSIE [1-6]\.(?!.*SV1)"; 
      gzip_http_version 1.1; 
      gzip_min_length 500; 
      gzip_vary on; 
      gzip_proxied any; 
      gzip_types 
          application/atom+xml 
          application/javascript 
          application/json 
          application/ld+json 
          application/manifest+json 
          application/rss+xml 
          application/vnd.geo+json 
          application/vnd.ms-fontobject 
          application/x-font-ttf 
          application/x-web-app-manifest+json 
          application/xhtml+xml 
          application/xml 
          font/opentype 
          image/bmp 
          image/svg+xml 
          image/x-icon 
          text/cache-manifest 
          text/css 
          text/plain 
          text/vcard 
          text/vnd.rim.location.xloc 
          text/vtt 
          text/x-component 
          text/x-cross-domain-policy 
          text/js 
          text/xml 
          text/javascript; 


          add_header X-Cache-Status $upstream_cache_status; 
          proxy_cache STATIC; 
          proxy_set_header Host $host; 

      ---->     proxy_ignore_headers Vary; <----- 

          proxy_cache_key $host$uri$is_args$args; 
          proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504; 
          proxy_pass -removed-; 

    } 



    } 
} 

当行 'proxy_ignore_headers不同;'已设置,所有内容都将缓存,包括HTML页面。当我删除这一行时,除了HTML页面之外,所有内容都被缓存。为什么是这样?

我希望Nginx能够缓存HTML页面,即使原始服务器正在发送Vary头文件。

我希望有人能帮助我:)。

响应头有:

因人而异:主机,内容的语言,内容类型,内容编码

回答

0

修正:

在Nginx的源代码中设定的最大的42 Vary标题使用的字符。在我的情况下,那里有51个字符,因此我的Vary头部被当作Vary处理:*(no-cache)。将最大值设置为84为我固定。

本文将更深入地解释它。

https://thedotproduct.org/nginx-vary-header-handling/

积分的家伙张贴的短文。