title: Nginx SPA Serving Static Files, Proxying API Calls, and Rewriting to /index.html
body: <p>So, I'd like to have an nginx.conf that...</p>
  
  <ol>
  <li>Serves all /static requests directly</li>
  <li>Proxies all /api requests to another local server (port 8200)</li>
  <li>Serves /index.html for all other requests (so, /contact/123 would really serve /index.html)</li>
  </ol>
  
  <p>Here is my current config...</p>
  
  <pre><code>server {
  listen                      80;
  server_name                 www.xyz.io;
  root                        /opt/xyz/www;
  
  location / {
      try_files $uri $uri/ @backend;
  }
  
  location @backend {
      proxy_pass http://127.0.0.1:8200;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "Upgrade";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I'm really not clear how to have all other requests serve /index.html though.  Ideas?</p>