title: Django Nginx Browser Caching Configuration
body: <p>I am trying to configure Nginx to leverage on static file caching on browser. 
  My configuration file is as following </p>
  
  <pre><code>server {
  
      listen   80;
      server_name localhost;
  
      client_max_body_size 4G;
  
      access_log /home/user/webapps/app_env/logs/nginx-access.log;
      error_log /home/user/webapps/app_env/logs/nginx-error.log;
  
      location /static/ {
          alias   /home/user/webapps/app_env/static/;
      }
  
      location /media/ {
          alias   /home/user/webapps/app_env/media/;
      }
  ...
  }
  </code></pre>
  
  <p>When I add in the following caching configuration, the server fails to load static files and I am not able to restart my Nginx.</p>
  
  <pre><code>location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
      expires 365d;
  }
  </code></pre>
  
  <p>The nginx-error log shows <code>open() "/usr/share/nginx/html/media/cover_photos/292f109e-17ef-4d23-b0b5-bddc80708d19_t‌​humbnail.jpeg" failed (2: No such file or directory)</code></p>
  
  <p>I have done quite some research online but cannot solve this problem.</p>
  
  <p>Can anyone help me or just give me some suggestions on implementing static file caching in Nginx?
  Thank you!</p>
  
  <p>Reference: <a href="https://www.digitalocean.com/community/questions/leverage-browser-caching-for-nginx" rel="nofollow">Leverage browser caching for Nginx</a></p>