Optimizing Nginx For Performance Pt2 : Caching Static Website Data

NGINX Tweaks and Performance Tips
  1. Optimizing Nginx For Performance Pt1 : Configure Worker Processes for NGINX
  2. Optimizing Nginx For Performance Pt2 : Caching Static Website Data
  3. Optimizing Nginx For Performance Pt3 : Disable Access Logs and Reduce Disk Writes

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

Tweaking NGINX for Performance

Tweaking NGINX for Performance Nginx is a widely-used open-source web server that can handle high traffic…

Write a comment