利用nginx的浏览器缓存

时间:2015-11-10 09:55:41

标签: caching nginx expires-header

我在 /etc/nginx/nginx.conf debian服务器中添加了expires 但它不会出现在网站文件的标题上:

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;
}

有人看到有什么问题吗? 我根本不是专家,我只是从教程中复制过来......

由于

1 个答案:

答案 0 :(得分:0)

我找到了。

这是因为我正在使用nginx和plesk。

我需要使用管理面板

来过期