title: nginx try_files from proxy'd app, then nginx
body: <p>I'm attempting to have nginx reverse proxy static files from an application if the application is serving them, else serve them itself. Currently, I have this configuration:</p>
  
  <pre><code>upstream app_server {
      server unix:/tmp/gunicorn.sock fail_timeout=0;
  }
  
  server {
      listen          8080;
      server_name     example.com;
      access_log      /var/log/nginx.access.log;
      error_log       /var/log/nginx.error.log;
  
      keepalive_timeout 5;
  
      location /static {
          try_files   $uri @proxy_to_app;
          alias       /path/to/__static;
          sendfile    off;
      }
  
      location / {
          try_files   $uri @proxy_to_app;
      }
  
      location @proxy_to_app {
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_redirect off;
  
          proxy_pass   http://app_server;
      }
  }
  </code></pre>
  
  <p>This works if the files don't exist in <code>/path/to/__static</code>; it sends the request to the application server. However, if the files also exist in <code>/path/to/__static</code>, nginx serves the files itself.</p>
  
  <p>Reversing the <code>try_files</code> line (<code>try_files @proxy_to_app $uri</code>) fails in both cases. If the client requests <code>/static/css/test.css</code>, the application receives a request for <code>/css/test.css</code>, and it never seems to try <code>/path/to/__static</code> even though the application returns a 404.</p>
  
  <p>Updated to include full configuration.</p>