title: nginx rewrite - proxy if file not exists
body: <p>I have a local directory (uploads) and an <strong>S3</strong> bucket setup.
  when the user is uploading an image the file is stored on the local directory: <code>/uploads/member_id/image_name</code>
  and after 30 minutes the system is uploading the files to <strong>S3</strong> with the same path: <code>s3.amazonaws.com/bucket/member_id/image_name;</code></p>
  
  <p>I have setup this rewrite rule on my nginx server but it's not working.
  this rule should check if the file is exists locally, and if not, open a proxy to <strong>S3</strong>..</p>
  
  <p>Any idea how to fix it? </p>
  
  <pre><code>location /uploads/
  {
      rewrite  ^/uploads/(.*)/([A-Za-z0-9\._]*)$ /uploads/$1/$2?imgname=$2&amp;member=$1;
      try_files $uri @fallback;
  }
  
  location @fallback
  {
      resolver 8.8.8.8;
      proxy_pass $scheme://s3.amazonaws.com/bucket/$arg_member/$arg_imgname;
      proxy_set_header Host s3.amazonaws.com;
  }
  </code></pre>