title: nginx + nodejs configuration
body: <p>I have a problem with my current nginx configuration. What I am trying to do is:</p>
  
  <ul>
  <li>For requests without any path, get the index.html (works)</li>
  <li>Get existing files directly (works)</li>
  <li>If the requested file or path does not physically exist, proxy request to nodejs (404)</li>
  </ul>
  
  <p>I have tried several configurations found here on stackoverflow, but none of them fit my needs.</p>
  
  <p>Here is my current configuration:</p>
  
  <pre><code># IP which nodejs is running on
  upstream app_x {
      server 127.0.0.1:3000;
  }
  
  # nginx server instance
  server {
  listen 80;
  server_name x.x.x.x;
  #access_log /var/log/nginx/x.log;
  
  root /var/www/x/public;
  
  location / {
      root /var/www/x/public;
      index index.html index.htm index.php;
  }
  
  location ^/(.*)$ {
      if (-f $request_filename) {
          break;
      }
      proxy_set_header Host $http_host;
      proxy_pass http://127.0.0.1:3000;
  }
  }
  </code></pre>