Linux 无法配置NGINX以缓存映像

Linux 无法配置NGINX以缓存映像,linux,caching,ubuntu,nginx,Linux,Caching,Ubuntu,Nginx,我一直在尝试缓存存储在nginx服务器中的图像,我对nginx非常陌生,我已经安装了它并用php5 fpm配置了它,我已经阅读了许多关于缓存图像和php文件的教程。我已成功缓存PHP文件,但无法缓存图像。此处是nginx配置文件的一部分: fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m; fastcgi_cache_key "$scheme$request_method$host$r

我一直在尝试缓存存储在nginx服务器中的图像,我对nginx非常陌生,我已经安装了它并用php5 fpm配置了它,我已经阅读了许多关于缓存图像和php文件的教程。我已成功缓存PHP文件,但无法缓存图像。此处是nginx配置文件的一部分:

fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
add_header X-Cache $upstream_cache_status;

server {    
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.html index.htm;

# Make site accessible from http://localhost/
server_name localhost;

set $skip_cache 0;

# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
    set $skip_cache 1;
}   
if ($query_string != "") {
    set $skip_cache 1;
}   

location / {
    try_files $uri $uri/ /index.php?$args;
}  

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;

    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_cache MYAPP;
    fastcgi_cache_valid 200 60m;

}

location ~* ^.+\.(jpg|jpeg|gif|png)$ {
    access_log off; log_not_found off; expires 1d;
}

location ~ /\. { deny  all; access_log off; log_not_found off; }
}
现在当我运行curl-I时http://xxx.xxx.xxx.xxx/script.php 我可以看到在/etc/nginx/cache文件夹中创建的脚本的md5,也可以看到X-cache:HIT

但是,当我运行curl-I时http://xxx.xxx.xxx.xxx/image.jpg 在/etc/nginx/cache中没有创建任何文件,我在控制台中得到以下结果:

HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Tue, 17 Jun 2014 08:14:37 GMT
Content-Type: image/jpeg
Content-Length: 55936
Last-Modified: Tue, 17 Jun 2014 04:30:11 GMT
Connection: keep-alive
ETag: "539fc453-da80"
Expires: Wed, 18 Jun 2014 08:14:37 GMT
Cache-Control: max-age=86400
Accept-Ranges: bytes
现在它看起来很好,但是当我再次运行它时,到期日期将不断更改,好像它调用的是新图像而不是缓存

HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Tue, 17 Jun 2014 08:16:34 GMT
Content-Type: image/jpeg
Content-Length: 55936
Last-Modified: Tue, 17 Jun 2014 04:30:11 GMT
Connection: keep-alive
ETag: "539fc453-da80"
Expires: Wed, 18 Jun 2014 08:16:34 GMT
Cache-Control: max-age=86400
Accept-Ranges: bytes
我的问题是:

1-缓存的图像是否应显示在缓存文件夹中

2-fastcgi是否能够缓存图像

3-如何解决图像缓存问题


对于初学者的问题,我很抱歉,但我找不到答案。

图像是静态的,nginx不支持缓存静态文件,因为没有处理开销,只需添加过期时间,即可设置您的图像。这是您想要的图像缓存:@ManuelGutierrez感谢您的回复,请与我联系,因为我是新来的,现在我已添加了1天的过期时间,我为图像运行了curl,并获得了过期日期。当我再次运行curl时,到期日期会发生变化,不应该取第一个的到期日期吗?您可以从上面的输出中看到。curl没有像浏览器那样的缓存,每个请求都像第一次一样,因此nginx会发送自该时刻起的过期时间,请尝试最近的Firefox,使用Ctrl+Shift+I>网络并点击F5查看缓存的工作原理。@MGP抱歉,您错了;如果图像被调整大小或生成,该怎么办?它们实际上不必是静态文件。