Nginx – How to determine which request nginx sends to a proxy and which it serves

loggingnginx

I currently have nginx proxying for Thin, but set up to serve static files for the app that Thin is serving instead of proxying the request.

What I'd like to know is how I can check that the rules are set up correctly. Since Thin doesn't log requests, I would need to set up nginx logs in such a way that it shows which requests were served as files and which were passed to Thin. Is this even possible? If so, how?

Best Answer

Depending on your configuration, it may be easy to achieve. Here is my solution...

server {
  server_name domainname.com;
  root /path/to/files;
  # index index.php index.html;

  # logging of all requests in access.log
  access_log /some/path/such/as/var/log/nginx/access.log;

  location / {
    try_files $uri $uri @thin;
  }

  location @thin {
    # pass the requests to thin
    # proxy_pass http://thin;

    # proxy specific logging in proxy-access.log
    access_log /some/path/such/as/var/log/nginx/proxy-access.log;
  }
}

Hope this helps!