NGINX proxy_pass没有缓存内容

Cha*_*own 3 caching nginx

我在使用proxy_pass命令让NGINX缓存我从Dropbox中提取的缩略图时遇到问题.在NGINX运行的同一台服务器上,我多次运行以下命令

 wget --server-response --spider  http://localhost:8181/1/thumbnails/auto/test.jpg?access_token=123
Run Code Online (Sandbox Code Playgroud)

并使用X-Cache获得完全相同的响应:每次都是MISS

HTTP/1.1 200 OK服务器:nginx/1.1.19日期:2015年3月25日星期三20:05:36 GMT内容类型:image/jpeg内容长度:1691连接:keep-alive pragma:no-cache cache-control :no-cache X-Robots-Tag:noindex,nofollow,noimageindex X-Cache:MISS

这是我的nginx.conf文件的内容..关于我在这里做错了什么的想法?

## Proxy Server Caching
proxy_cache_path  /data/nginx/cache  keys_zone=STATIC:10m max_size=1g;


## Proxy Server Setting
server {
    listen *:8181;

    proxy_cache     STATIC;
    proxy_cache_key "$request_uri";
    proxy_cache_use_stale  error timeout invalid_header updating
                   http_500 http_502 http_503 http_504;

    location ~ ^/(.*) {
    set $dropbox_api 'api-content.dropbox.com';
    set $url    '$1';

    resolver 8.8.8.8;   

    proxy_set_header    Host    $dropbox_api;

    proxy_cache     STATIC;
    proxy_cache_key     "$request_uri";
    proxy_cache_use_stale   error timeout invalid_header updating
                   http_500 http_502 http_503 http_504;

    add_header X-Cache $upstream_cache_status; 

    proxy_pass https://$dropbox_api/$url$is_args$args;
    }

    ##Error Handling
    error_page 500 502 503 504 404 /error/;  
    location = /error/ {  
    default_type text/html;
    }   
}
Run Code Online (Sandbox Code Playgroud)

Cha*_*own 8

原来从Dropbox返回的缩略图请求包括标题

Cache-Control: no-cache
Run Code Online (Sandbox Code Playgroud)

并且Nginx将遵循这些标头,除非明确忽略它们,这可以通过简单地使用将忽略任何缓存控制的以下配置行来完成.

proxy_ignore_headers    X-Accel-Expires Expires Cache-Control;
Run Code Online (Sandbox Code Playgroud)

我们还遇到了将"proxy_ignore_headers"选项放在nginx.conf文件中的不同区域的问题.最后,经过多次游戏,我们通过在"位置"块中明确设置它来实现它.配置文件的完整片段可以在下面找到

    ## Proxy Server Caching
proxy_cache_path  /data/nginx/cache  levels=1:2 keys_zone=STATIC:50m inactive=2h max_size=2g;

## Proxy Server Setting
server {
    listen *:8181;

    location ~ ^/(.*) {
    set $dropbox_api 'api-content.dropbox.com';
    set $url    '$1';

    resolver 8.8.8.8;

    proxy_set_header    Host    $dropbox_api;
    proxy_hide_header   x-dropbox-thumbcachehit;
    proxy_hide_header   x-dropbox-metadata;
    proxy_hide_header   x-server-response-time;
    proxy_hide_header   x-dropbox-request-id;

    proxy_hide_header cache-control;
    proxy_hide_header expires;

    add_header cache-control "private";
    add_header x-cache $upstream_cache_status; # HIT / MISS / BYPASS / EXPIRED

    proxy_cache     STATIC;
    proxy_cache_valid       200  1d;
    proxy_cache_use_stale   error timeout invalid_header updating
                http_500 http_502 http_503 http_504;
    proxy_ignore_headers    X-Accel-Expires Expires Cache-Control;

    proxy_pass https://$dropbox_api/$url$is_args$args;
    }
}
Run Code Online (Sandbox Code Playgroud)