title: What in nginx determines what goes to rails and what is served directly?
body: <p>I have a nginx + thin + Rails 3.2 setup. Currently I am trying to setup nginx so it can serve cached pages directly.</p>
  
  <p>However nginx still pass *.html request to Rails in the following nginx configuration files. The html files exists in public folder, and nginx does find them, just that they are still passed to Rails.</p>
  
  <pre><code>upstream site {
    server unix:/home/site/deploy/site/shared/pids/thin.0.sock;
  }
  
  server {
    listen 80;
    server_name www.example.com;
    rewrite ^(/.*) http://example.com$1 permanent;
  }
  
  # asset server
  server {
    listen 80;
    server_name assets.example.com;
    expires max;
    add_header Cache-Control public;
    charset utf-8;
    root   /home/site/deploy/site/current/public/;
  }
  
  # frontend
  server {
    listen 80;
    server_name .example.com;
    charset utf-8;
  
    root   /home/site/deploy/site/current/public/;
    index  index.html;
  
    location ~* ^.+.(jpg|jpeg|gif|png|swf|zip|rar|doc|xls|exe|pdf|ppt|txt|tar)$ {
      root /home/site/deploy/site/current/public/;
      expires max;
      break;
    }
  
    # serve static files
    if (-f $request_filename) {
      break;
    }
  
    gzip on;
  
    location / {
      proxy_set_header  X-Real-IP  $remote_addr;
      proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
  
      if (-f $request_filename) {
        break;
      }
  
      if (-f $document_root/cache/$host/$uri/index.html) {
        rewrite (.*) /cache/$host/$1/index.html break;
      }
  
      if (-f $document_root/cache/$host/$uri.html) {
        rewrite (.*) /cache/$host/$1.html break;
      }
  
      if (-f $document_root/cache/$host/$uri) {
        rewrite (.*) /cache/$host/$1 break;
      }
  
      proxy_pass http://site;
      break;
    }
  }
  </code></pre>
  
  <p>I am new to nginx, and this configuration file is copied from previous projects I have not worked on, so this is probably a very newbie question.</p>