title: nginx configuration for expiration specifying
body: <p>I am trying to improve my pagespeed. I have installed nginx and changed my sites to http2. But  in the gtmetrix Performance Report my css,png and js files has no expiration dates. (expiration not specified) in the Leverage browser caching recommendation. I think I have set all possible ways to do this and tried different variants.</p>
  
  <p>If their are another improvements in my nginx instrution and htaccess file, feel free to post it. </p>
  
  <p>nginx addictional  instructions in Plesk</p>
  
  <pre><code>gzip on;
  gzip_vary on;
  gzip_min_length 1240;
  gzip_proxied    expired no-cache no-store private auth;
  gzip_disable "MSIE [1-6]\\.(?!.*SV1)";
  gzip_proxied any;
  gzip_types text/plain text/css text/javascript application/javascript application/x-javascript application/json text/xml application/xml application/xml+rss image/x-icon image/bmp image/svg+xml;
  location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
      expires 1y;
      log_not_found off;
  }
  </code></pre>
  
  <p>htaccess-file</p>
  
  <pre><code>&lt;IfModule mod_deflate.c&gt;
     AddOutputFilterByType DEFLATE text/plain text/html
     AddOutputFilterByType DEFLATE text/css text/javascript
  &lt;/IfModule&gt;
  
  &lt;IfModule mod_deflate.c&gt;            
  &lt;FilesMatch “\\.(js|css|html|xml)$”&gt;
  SetOutputFilter DEFLATE
  &lt;/FilesMatch&gt;
  &lt;/IfModule&gt;
  
  &lt;IfModule mod_gzip.c&gt;
     mod_gzip_on       Yes
     mod_gzip_dechunk  Yes
     mod_gzip_item_include file      \.(html?|txt|css|js|php|pl)$
     mod_gzip_item_include handler   ^cgi-script$
     mod_gzip_item_include mime      ^text/.*
     mod_gzip_item_include mime      ^application/x-javascript.*
     mod_gzip_item_exclude mime      ^image/.*
     mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
  &lt;/IfModule&gt;           
  
  &lt;IfModule mod_expires.c&gt;
  ExpiresActive On
  ExpiresByType text/html "access plus 500 seconds"
  ExpiresByType text/xml "access plus 3600 seconds"
  ExpiresByType image/gif "access plus 14 days"
  ExpiresByType image/ico "access plus 14 days"
  ExpiresByType image/jpeg "access plus 14 days"
  ExpiresByType image/jpg "access plus 14 days"
  ExpiresByType image/png "access plus 14 days"
  ExpiresByType text/css "access plus 14 days"
  ExpiresByType text/javascript "access plus 14 days"
  ExpiresByType application/x-javascript "access plus 14 days"
  ExpiresByType application/javascript "access plus 14 days"
  ExpiresByType application/x-shockwave-flash "access plus 1000 seconds"
  ExpiresByType application/xhtml+xml "access plus 6000 seconds"
  &lt;/IfModule&gt;
  
  &lt;IfModule mod_headers.c&gt;
  &lt;FilesMatch "\\.(ico|jpeg|jpg|png|gif|swf)$"&gt;
  Header set Cache-Control "max-age=2629743, public"
  &lt;/FilesMatch&gt;
  &lt;FilesMatch "\\.(css)$"&gt;
  Header set Cache-Control "max-age=2592000, public"
  &lt;/FilesMatch&gt;
  &lt;FilesMatch "\\.(js)$"&gt;
  Header set Cache-Control "max-age=216000, private"
  &lt;/FilesMatch&gt;
  #&lt;FilesMatch "\\.(xhtml|html|htm|php)$"&gt;
  #Header set Cache-Control "max-age=600, private, must-revalidate"
  #&lt;/FilesMatch&gt;
  &lt;/IfModule&gt;        
  
  AddType application/x-httpd-php .xml
  </code></pre>