about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-01-25 13:58:29 -0800
committerEric Wong <normalperson@yhbt.net>2011-01-25 13:58:29 -0800
commit09afcf2ce9fc89d77b6b282bbf00a78c73741a4b (patch)
tree07a065ba8b873cb22187f74ee3e269c3e9aec20a
parent1ca83b055375ab7e72d383ffd0f36f70c07d9e92 (diff)
downloadunicorn-09afcf2ce9fc89d77b6b282bbf00a78c73741a4b.tar.gz
This feature is in nginx 0.7.x and 0.8.x and optimized
better than the "if" directive in nginx.conf

ref: http://wiki.nginx.org/Pitfalls
ref: http://wiki.nginx.org/IfIsEvil
-rw-r--r--examples/nginx.conf18
1 files changed, 11 insertions, 7 deletions
diff --git a/examples/nginx.conf b/examples/nginx.conf
index 70d1851..52ec245 100644
--- a/examples/nginx.conf
+++ b/examples/nginx.conf
@@ -98,7 +98,16 @@ http {
     # path for static files
     root /path/to/app/current/public;
 
-    location / {
+    # Prefer to serve static files directly from nginx to avoid unnecessary
+    # data copies from the application server.
+    #
+    # try_files directive appeared in in nginx 0.7.27 and has stabilized
+    # over time.  Older versions of nginx (e.g. 0.6.x) requires
+    # "if (!-f $request_filename)" which was less efficient:
+    # http://bogomips.org/unicorn.git/tree/examples/nginx.conf?id=v3.3.1#n127
+    try_files $uri/index.html $uri.html $uri @app;
+
+    location @app {
       # an HTTP header important enough to have its own Wikipedia entry:
       #   http://en.wikipedia.org/wiki/X-Forwarded-For
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
@@ -122,12 +131,7 @@ http {
       # clients, really.
       # proxy_buffering off;
 
-      # Try to serve static files from nginx, no point in making an
-      # *application* server like Unicorn/Rainbows! serve static files.
-      if (!-f $request_filename) {
-        proxy_pass http://app_server;
-        break;
-      }
+      proxy_pass http://app_server;
     }
 
     # Rails error pages