Optimizing Nginx For Performance Pt2 : Caching Static Website Data

NGINX Tweaks and Performance Tips

Part 2: Cache Static Content:

Content Caching Explained: Data Caching is the process of storing data for faster retrieval. In the case of Nginx, it’s the temporary storage of web pages in order to reduce bandwidth and improve performance. When someone visits your website the cached version will be served to the visitor unless it has been modified.

Enabling Caching
Within your Nginx configuration, you can add the following to your server{} directive to tell your computer to cache the web page’s static files  for faster accessibility. In the example below, we are caching .ico, .css, .js, .gif, .jpg and .png files.

location ~* \.(?:ico|css|js|gif|jpg|png)$ {
        expires 30d;
        add_header Vary Accept-Encoding;
                access_log off;



Founder & CEO

Lyron Foster is a Prolific Multinational Serial Entrepreneur, Blogger, Author, IT Trainer, Polyglot Coder, Real Estate Investor and Technologist.

Related Posts

Write a comment