title: Serve static files based on dynamic URLs with Flask+Nginx?
body: <p>In Flask, if you place a file in a directory called <code>static/</code>, then any URL of the form <code>http://localhost/static/foo.jpg</code> will serve that file from <code>static/foo.jpg</code>.</p>
  
  <p>This can also be accomplished via an nginx config:</p>
  
  <pre><code>    location /static {
          alias    /var/www/mywebsite/static;
      }
  </code></pre>
  
  <p>However, I want to do dynamic URL rewriting.</p>
  
  <p>If someone requests the URL <code>http://localhost/username/foo.jpg</code>, I want to tell nginx to fetch the static file from an arbitrary URL, say, <code>/var/www/assets/11235/1bcd5.jpg</code>. I want the user to see a pretty url, and I want the location to be transparent to the user.</p>
  
  <p>Is there an easy way to do this? Ideally, I would be able to do something so that nginx serves the file. However, if Flask needs to serve it, then that is fine too (it isn't like my project has any users yet!)</p>
  
  <p>What am I missing here?</p>