title: Nginx serving images
body: <p>Trying to generate image if it's not exists via Nginx redirect to script, but have problems with this simple issue. 
  Wrote following config (tried different variants, this is the last), but it still wont works.</p>
  
  <pre><code>location /img/(\d+)\.(jpg|png|gif)$ {
         root /path/to/img_dir;
         expires max;
         add_header Pragma public;
         add_header Cache-Control "public";
         try_files $1.$2 http://site.com/generate_img/$1.$2;
  }
  </code></pre>
  
  <p>Also used this code insted of <code>try_files</code>:</p>
  
  <pre><code>if (!-f $document_root/$1.$2) {
       rewrite ^ http://site.com/generate_img/$1.$2;
  }
  </code></pre>