利用 nginx 的浏览器缓存

Leverage browser caching with nginx

我在 /etc/nginx/nginx.conf debian 服务器中添加了 expires 但是它没有出现在 header 的网站文件中:

Accept-Ranges       bytes
Cache-Control       public
Connection      keep-alive
Content-Length    122623
Content-Type        image/jpeg
Date        Tue, 10 Nov 2015 09:48:45 GMT
Etag        "561cb1f6-1deff"
Last-Modified    Tue, 13 Oct 2015 07:25:42 GMT
Server      nginx
X-Powered-By    PleskLin

这是我的 nginx.conf :

#user  nginx;
worker_processes  auto;

#error_log  /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

#pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
    multi_accept on;
}


http {

    client_header_timeout 3000;
    client_body_timeout 3000;
    fastcgi_read_timeout 3000;
    fastcgi_send_timeout 3000;
    fastcgi_connect_timeout 3000;
    client_max_body_size 32m;
    fastcgi_buffers 16 128k;
    fastcgi_buffer_size 128k;
proxy_buffers 16 128k;
proxy_buffer_size 128k;

    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    #tcp_nodelay        on;

    gzip  on;
#gzip_disable "MSIE [1-6]\.(?!.*SV1)";

gzip_comp_level 9;
gzip_http_version 1.1;
gzip_proxied any;
gzip_min_length 10;
gzip_buffers 16 8k;
gzip_types text/plain text/css application/javascript text/xml application/xml application/xml+rss text/javascript application/xhtml+xml;

# Disable for IE < 6 because there are some known problems
gzip_disable “MSIE [1-6].(?!.*SV1)”;

# Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6
gzip_vary on;

    server_tokens off;








server {
        listen 80;
        index index.php index.html;

# Expire rules for static content

# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
  expires -1;
  # access_log logs/static.log; # I don't usually include a static log
}

# Feed
location ~* \.(?:rss|atom)$ {
  expires 1h;
  add_header Pragma public;
  add_header Cache-Control "public";
}

# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
  expires 1M;
  access_log off;
  add_header Pragma public;
  add_header Cache-Control "public";
}

# CSS and Javascript
location ~* \.(?:css|js)$ {
  expires 1y;
  access_log off;
  add_header Pragma public;
  add_header Cache-Control "public";
}

}



    include /etc/nginx/conf.d/*.conf;
}

有人知道问题出在哪里吗? 我根本不是专家,我只是从教程中复制过去...

谢谢

我找到了。

因为我在 plesk 中使用 nginx。

我需要在管理面板中设置过期时间