title: Flask app gives ubiquitous 404 when proxied through nginx
body: <p>I've got a flask app daemonized via supervisor. I want to proxy_pass a subfolder on the localhost to the flask app. The flask app runs correctly when run directly, however it gives 404 errors when called through the proxy. Here is the config file for nginx:</p>
  
  <pre><code>upstream apiserver {
      server 127.0.0.1:5000;
  }
  
  location /api {
              rewrite /api/(.*) /$1 break;
              proxy_pass_header Server;
              proxy_set_header Host $http_host;
              proxy_set_header X-Real-IP $remote_addr;
              proxy_set_header X-Scheme $scheme;
              proxy_pass http://apiserver;
              proxy_next_upstream error timeout http_502;
              proxy_buffering off;
  
  }
  </code></pre>
  
  <p>For instance, when I go to <code>http://127.0.0.1:5000/me</code>, I get a valid response from the app. However when I go to <code>http://127.0.0.1/api/me</code> I get a 404 from the flask app (not nginx). Also, the flask <code>SERVER_NAME</code> variable is set to <code>127.0.0.1:5000</code>, if that's important.</p>
  
  <p>I'd really appreciate any suggestions; I'm pretty stumped! If there's anything else I need to add, let me know!</p>