cachingnginxexpires-header

Leverage browser caching with nginx


I added expires in my /etc/nginx/nginx.conf debian server But it don't appear on the header of website files :

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

Here is my 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;
}

Anyone see what is the problem ? I'm not an expert at all, I just copy past from tutorial...

Thanks


Solution

  • I found it.

    It's because I'm using nginx with plesk.

    I need to put the expires with the admin panel